use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class VreAuthorizationTest method isAllowedToWriteReturnsTrueIfTheRolesContainUser.
@Test
public void isAllowedToWriteReturnsTrueIfTheRolesContainUser() throws Exception {
VreAuthorization instance = VreAuthorization.create("", "", USER_ROLE);
boolean allowedToWrite = instance.isAllowedToWrite();
assertThat(allowedToWrite, is(true));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class AzureAccessTest method testVreAuthorization.
@Test
public void testVreAuthorization() throws Exception {
AzureVreAuthorizationAccess instance = new AzureVreAuthorizationAccess(tableClient);
Optional<VreAuthorization> beforeCreate = instance.getAuthorization("vreId", "userId");
VreAuthorization created = instance.getOrCreateAuthorization("vreId", "userId", "role1");
Optional<VreAuthorization> afterCreate = instance.getAuthorization("vreId", "userId");
assertThat(beforeCreate, is(not(present())));
assertThat(afterCreate.get(), is(created));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class LocalFileVreAuthorizationAccessTest method getAuthorizationCheckesTheGeneralAccessOfTheUserWhenHeHasNoAccessOnTheDataSet.
@Test
public void getAuthorizationCheckesTheGeneralAccessOfTheUserWhenHeHasNoAccessOnTheDataSet() throws Exception {
File file = new File(authorizationsFolder.toFile(), "authorizations.json");
file.createNewFile();
String testAuthInfo = "[{\"vreId\":\"test_vre\",\"userId\":\"33707283d426f900d4d33707283d426f9testing\"," + "\"roles\":[\"ADMIN\"]}]\n";
Files.write(file.toPath(), testAuthInfo.getBytes());
String userId = "33707283d426f900d4d33707283d426f9testing";
Optional<VreAuthorization> authorization = instance.getAuthorization(VRE, userId);
assertThat(authorization, is(present()));
assertThat(authorization.get().hasAdminAccess(), is(true));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class LocalFileVreAuthorizationAccessTest method addAuthorizationIgnoresTheSecondAdditionForUserToAVre.
@Test
public void addAuthorizationIgnoresTheSecondAdditionForUserToAVre() throws Exception {
String unknownUser = "unknownUser";
instance.getOrCreateAuthorization(VRE, unknownUser, UNVERIFIED_USER_ROLE);
VreAuthorization authorization2 = instance.getOrCreateAuthorization(VRE, unknownUser, ADMIN_ROLE);
assertThat(authorization2.getRoles(), contains(UNVERIFIED_USER_ROLE));
}
use of nl.knaw.huygens.timbuctoo.security.dto.VreAuthorization in project timbuctoo by HuygensING.
the class LocalFileVreAuthorizationAccessTest method setup.
@Before
public void setup() throws Exception {
authorizationsFolder = makeTempDir();
vreAuthPath = authorizationsFolder.resolve(VRE);
vreAuthPath.toFile().mkdirs();
VreAuthorization[] authorizations = { VreAuthorization.create(VRE, USER_ID, "USER"), VreAuthorization.create(VRE, USER_ID_WITHOUT_WRITE_PERMISSIONS, UNVERIFIED_USER_ROLE) };
File file = vreAuthPath.resolve(AUTH_FILE).toFile();
objectMapper = new ObjectMapper();
objectMapper.writeValue(file, authorizations);
instance = new LocalFileVreAuthorizationAccess(authorizationsFolder);
}
Aggregations