use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class AppFabricTestBase method getSystemProfile.
protected Optional<Profile> getSystemProfile(String profileName, int expectedCode) throws Exception {
HttpResponse response = doGet(String.format("/v3/profiles/%s", profileName));
assertResponseCode(expectedCode, response);
if (expectedCode == HttpResponseStatus.OK.code()) {
return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class));
}
return Optional.empty();
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandlerTest method testSystemNamespaceProfilesNotAllowed.
@Test
public void testSystemNamespaceProfilesNotAllowed() throws Exception {
listProfiles(NamespaceId.SYSTEM, false, HttpURLConnection.HTTP_BAD_METHOD);
getProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
disableProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
enableProfile(NamespaceId.SYSTEM.profile("abc"), HttpURLConnection.HTTP_BAD_METHOD);
Profile profile = new Profile("abc", "label", "desc", new ProvisionerInfo("xyz", Collections.emptyList()));
putProfile(NamespaceId.SYSTEM.profile("abc"), profile, HttpURLConnection.HTTP_BAD_METHOD);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandlerTest method testPutAndDeleteProfiles.
@Test
public void testPutAndDeleteProfiles() throws Exception {
Profile invalidProfile = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo("nonExisting", PROPERTY_SUMMARIES));
// adding a profile with non-existing provisioner should get a 400
putProfile(NamespaceId.DEFAULT.profile(invalidProfile.getName()), invalidProfile, HttpURLConnection.HTTP_BAD_REQUEST);
// put a profile with the mock provisioner
Profile expected = new Profile("MyProfile", "label", "my profile for testing", new ProvisionerInfo(MockProvisioner.NAME, PROPERTY_SUMMARIES));
ProfileId expectedProfileId = NamespaceId.DEFAULT.profile(expected.getName());
putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
// get the profile
Profile actual = getProfile(expectedProfileId, HttpURLConnection.HTTP_OK).get();
Assert.assertEquals(expected, actual);
// list all profiles, should get 2 profiles
List<Profile> profiles = listProfiles(NamespaceId.DEFAULT, true, HttpURLConnection.HTTP_OK);
Set<Profile> expectedList = ImmutableSet.of(Profile.NATIVE, expected);
Assert.assertEquals(expectedList.size(), profiles.size());
Assert.assertEquals(expectedList, new HashSet<>(profiles));
// adding the same profile should still succeed
putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
// get non-existing profile should get a 404
deleteProfile(NamespaceId.DEFAULT.profile("nonExisting"), HttpURLConnection.HTTP_NOT_FOUND);
// delete the profile should fail first time since it is by default enabled
deleteProfile(expectedProfileId, HttpURLConnection.HTTP_CONFLICT);
// disable the profile then delete should work
disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
Assert.assertEquals(Collections.emptyList(), listProfiles(NamespaceId.DEFAULT, false, HttpURLConnection.HTTP_OK));
// if given some unrelated json, it should return a 400 instead of 500
ProvisionerSpecification spec = new MockProvisioner().getSpec();
ProvisionerDetail test = new ProvisionerDetail(spec.getName(), spec.getLabel(), spec.getDescription(), new ArrayList<>(), null, null, false);
putProfile(NamespaceId.DEFAULT.profile(test.getName()), test, HttpURLConnection.HTTP_BAD_REQUEST);
doAs(READ_ONLY_USER_NAME, () -> {
putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_FORBIDDEN);
disableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
enableProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
deleteProfile(expectedProfileId, HttpURLConnection.HTTP_FORBIDDEN);
});
doAs(READ_WRITE_USER_NAME, () -> {
putProfile(expectedProfileId, expected, HttpURLConnection.HTTP_OK);
disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
enableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
disableProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
deleteProfile(expectedProfileId, HttpURLConnection.HTTP_OK);
});
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandlerTest method testNullProvisionerProperty.
@Test
public void testNullProvisionerProperty() throws Exception {
// provide a profile with null provsioner property, it should still succeed
List<ProvisionerPropertyValue> listWithNull = new ArrayList<>();
listWithNull.add(null);
Profile profile = new Profile("ProfileWithNull", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listWithNull));
putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
// Get the profile, it should not contain the null value, the property should be an empty list
Profile actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
Assert.assertNotNull(actual);
Assert.assertEquals(Collections.EMPTY_SET, actual.getProvisioner().getProperties());
disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
// provide a profile with mixed properties with null, it should still succeed
List<ProvisionerPropertyValue> listMixed = new ArrayList<>(PROPERTY_SUMMARIES);
listMixed.addAll(listWithNull);
profile = new Profile("ProfileMixed", "label", "should succeed", new ProvisionerInfo(MockProvisioner.NAME, listMixed));
putProfile(NamespaceId.DEFAULT.profile(profile.getName()), profile, HttpURLConnection.HTTP_OK);
// Get the profile, it should not contain the null value, the property should be all non-null properties in the list
actual = getProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK).get();
Assert.assertNotNull(actual);
Assert.assertEquals(PROPERTY_SUMMARIES, actual.getProvisioner().getProperties());
disableProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
deleteProfile(NamespaceId.DEFAULT.profile(profile.getName()), HttpURLConnection.HTTP_OK);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandlerTest method testPutPermissionChecks.
@Test
public void testPutPermissionChecks() throws Exception {
Profile profile = new Profile(PERMISSIONS_TEST_PROFILE, "label", "default permissions testing profile", new ProvisionerInfo(MockProvisioner.NAME, Collections.emptyList()));
ProfileId profileId = NamespaceId.DEFAULT.profile(PERMISSIONS_TEST_PROFILE);
// Verify the UPDATE user does not have permissions to create a profile
doAs(UPDATE_PROFILE_USER.getName(), () -> {
putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
});
// Verify that the CREATE user can create both profiles
doAs(CREATE_PROFILE_USER.getName(), () -> {
putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
});
// Verify that the UPDATE user can modify the profiles after they have been created
doAs(UPDATE_PROFILE_USER.getName(), () -> {
putProfile(profileId, profile, HttpURLConnection.HTTP_OK);
putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_OK);
// Disable the profiles in preparation for deletion.
disableProfile(profileId, HttpURLConnection.HTTP_OK);
disableSystemProfile(profile.getName(), HttpURLConnection.HTTP_OK);
// Verify deletion failure
deleteProfile(profileId, HttpURLConnection.HTTP_FORBIDDEN);
deleteSystemProfile(profile.getName(), HttpURLConnection.HTTP_FORBIDDEN);
});
// Verify that the CREATE user cannot update profiles after they have been created
doAs(CREATE_PROFILE_USER.getName(), () -> {
putProfile(profileId, profile, HttpURLConnection.HTTP_FORBIDDEN);
putSystemProfile(profile.getName(), profile, HttpURLConnection.HTTP_FORBIDDEN);
});
// Delete profiles
doAs(DELETE_PROFILE_USER.getName(), () -> {
deleteProfile(profileId, HttpURLConnection.HTTP_OK);
deleteSystemProfile(profile.getName(), HttpURLConnection.HTTP_OK);
});
}
Aggregations