Search in sources :

Example 1 with CheckAuthorizationRequest

use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest 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);
}
Also used : CheckAuthorizationResult(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult) CheckAuthorizationRequest(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest) IntegrationTestSupportService(org.haiku.haikudepotserver.IntegrationTestSupportService) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CheckAuthorizationRequest

use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest 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);
}
Also used : CheckAuthorizationResult(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult) CheckAuthorizationRequest(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest) IntegrationTestSupportService(org.haiku.haikudepotserver.IntegrationTestSupportService) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with CheckAuthorizationRequest

use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest 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();
}
Also used : CheckAuthorizationResult(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult) ObjectContext(org.apache.cayenne.ObjectContext) CheckAuthorizationRequest(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with CheckAuthorizationRequest

use of org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest 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();
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) Permission(org.haiku.haikudepotserver.security.model.Permission) CheckAuthorizationResult(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult) ObjectContext(org.apache.cayenne.ObjectContext) CheckAuthorizationRequest(org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) PermissionUserPkg(org.haiku.haikudepotserver.dataobjects.PermissionUserPkg) PermissionUserPkg(org.haiku.haikudepotserver.dataobjects.PermissionUserPkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)4 CheckAuthorizationRequest (org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationRequest)4 CheckAuthorizationResult (org.haiku.haikudepotserver.api1.model.authorization.CheckAuthorizationResult)4 Test (org.junit.jupiter.api.Test)4 ObjectContext (org.apache.cayenne.ObjectContext)2 IntegrationTestSupportService (org.haiku.haikudepotserver.IntegrationTestSupportService)2 PermissionUserPkg (org.haiku.haikudepotserver.dataobjects.PermissionUserPkg)1 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)1 User (org.haiku.haikudepotserver.dataobjects.User)1 Permission (org.haiku.haikudepotserver.security.model.Permission)1