use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult in project haikudepotserver by haiku.
the class AuthorizationApiIT method checkAuthorizationRequest_asRoot.
// TODO : when some more sophisticated cases are available; implement some better tests
@Test
public void checkAuthorizationRequest_asRoot() {
IntegrationTestSupportService.StandardTestData data = integrationTestSupportService.createStandardTestData();
setAuthenticatedUserToRoot();
CheckAuthorizationRequest request = new CheckAuthorizationRequest();
request.targetAndPermissions = new ArrayList<>();
request.targetAndPermissions.add(new CheckAuthorizationRequest.AuthorizationTargetAndPermission(AuthorizationTargetType.PKG, data.pkg1.getName(), Permission.PKG_EDITICON.name()));
// ------------------------------------
CheckAuthorizationResult result = authorizationApi.checkAuthorization(request);
// ------------------------------------
Assertions.assertThat(result.targetAndPermissions.size()).isEqualTo(1);
assertTargetAndPermission(data, result.targetAndPermissions.get(0), true);
}
use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult in project haikudepotserver by haiku.
the class AuthorizationApiIT method checkAuthorizationRequest_asUnauthenticated.
@Test
public void checkAuthorizationRequest_asUnauthenticated() {
IntegrationTestSupportService.StandardTestData data = integrationTestSupportService.createStandardTestData();
CheckAuthorizationRequest request = new CheckAuthorizationRequest();
request.targetAndPermissions = new ArrayList<>();
request.targetAndPermissions.add(new CheckAuthorizationRequest.AuthorizationTargetAndPermission(AuthorizationTargetType.PKG, data.pkg1.getName(), Permission.PKG_EDITICON.name()));
// ------------------------------------
CheckAuthorizationResult result = authorizationApi.checkAuthorization(request);
// ------------------------------------
Assertions.assertThat(result.targetAndPermissions.size()).isEqualTo(1);
assertTargetAndPermission(data, result.targetAndPermissions.get(0), false);
}
use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult in project haikudepotserver by haiku.
the class AuthorizationApiIT method checkAuthorizationRequest_asUserWithoutRule.
/**
* <P>With a user-pkg rule missing we should see this authorization come through in a check
* for that permission against the package being false.</P>
*/
@Test
public void checkAuthorizationRequest_asUserWithoutRule() {
integrationTestSupportService.createStandardTestData();
{
ObjectContext context = serverRuntime.newContext();
integrationTestSupportService.createBasicUser(context, "testuser1", "fakepassword");
}
CheckAuthorizationRequest request = new CheckAuthorizationRequest();
request.targetAndPermissions = new ArrayList<>();
request.targetAndPermissions.add(new CheckAuthorizationRequest.AuthorizationTargetAndPermission(AuthorizationTargetType.PKG, "pkg1", Permission.PKG_EDITICON.name()));
setAuthenticatedUser("testuser1");
// ------------------------------------
CheckAuthorizationResult result = authorizationApi.checkAuthorization(request);
// ------------------------------------
Assertions.assertThat(result.targetAndPermissions.size()).isEqualTo(1);
Assertions.assertThat(result.targetAndPermissions.get(0).authorized).isFalse();
}
use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult in project haikudepotserver by haiku.
the class AuthorizationApiIT method checkAuthorizationRequest_asUserWithRule.
/**
* <P>With a user-pkg rule in place we should see this authorization come through in a check
* for that permission against the package being true.</P>
*/
@Test
public void checkAuthorizationRequest_asUserWithRule() {
integrationTestSupportService.createStandardTestData();
{
ObjectContext context = serverRuntime.newContext();
User user1 = integrationTestSupportService.createBasicUser(context, "testuser1", "fakepassword");
integrationTestSupportService.agreeToUserUsageConditions(context, user1);
Pkg pkg1 = Pkg.tryGetByName(context, "pkg1").get();
org.haiku.haikudepotserver.dataobjects.Permission permission = org.haiku.haikudepotserver.dataobjects.Permission.getByCode(context, Permission.PKG_EDITICON.name().toLowerCase()).get();
PermissionUserPkg pup_u1p1 = context.newObject(PermissionUserPkg.class);
pup_u1p1.setPkg(pkg1);
pup_u1p1.setUser(user1);
pup_u1p1.setPermission(permission);
context.commitChanges();
}
CheckAuthorizationRequest request = new CheckAuthorizationRequest();
request.targetAndPermissions = new ArrayList<>();
request.targetAndPermissions.add(new CheckAuthorizationRequest.AuthorizationTargetAndPermission(AuthorizationTargetType.PKG, "pkg1", Permission.PKG_EDITICON.name()));
setAuthenticatedUser("testuser1");
// ------------------------------------
CheckAuthorizationResult result = authorizationApi.checkAuthorization(request);
// ------------------------------------
Assertions.assertThat(result.targetAndPermissions.size()).isEqualTo(1);
Assertions.assertThat(result.targetAndPermissions.get(0).authorized).isTrue();
}
Aggregations