Search in sources :

Example 6 with Login

use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.

the class JsonBasedAuthenticatorTest method createLoginIgnoresTheAdditionOfLoginOfAKnownUserName.

@Test
public void createLoginIgnoresTheAdditionOfLoginOfAKnownUserName() throws Exception {
    Login[] logins = new Login[0];
    Path emptyLoginsFile = FileHelpers.makeTempFilePath(true);
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.writeValue(emptyLoginsFile.toFile(), logins);
    JsonBasedAuthenticator instance = backedByFile(emptyLoginsFile);
    String userName = "userName";
    instance.createLogin("userPid", userName, "password", "givenName", "surname", "email", "org");
    instance.createLogin("userPid2", userName, "password1", "givenName2", "surname2", "email2", "org2");
    List<Login> loginList = objectMapper.readValue(emptyLoginsFile.toFile(), new TypeReference<List<Login>>() {
    });
    long count = loginList.stream().filter(login -> Objects.equals(login.getUsername(), userName)).count();
    assertThat(count, is(1L));
    Files.delete(emptyLoginsFile);
}
Also used : Path(java.nio.file.Path) FileHelpers(nl.knaw.huygens.timbuctoo.util.FileHelpers) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CoreMatchers.not(org.hamcrest.CoreMatchers.not) Test(org.junit.Test) JsonBasedAuthenticatorStubs.backedByFile(nl.knaw.huygens.timbuctoo.security.JsonBasedAuthenticatorStubs.backedByFile) Objects(java.util.Objects) LocalLoginUnavailableException(nl.knaw.huygens.timbuctoo.security.exceptions.LocalLoginUnavailableException) List(java.util.List) Rule(org.junit.Rule) JsonBasedAuthenticatorStubs.throwingWithAlgorithm(nl.knaw.huygens.timbuctoo.security.JsonBasedAuthenticatorStubs.throwingWithAlgorithm) Paths(java.nio.file.Paths) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Is.is(org.hamcrest.core.Is.is) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Login(nl.knaw.huygens.timbuctoo.security.dto.Login) ExpectedException(org.junit.rules.ExpectedException) Path(java.nio.file.Path) LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) Before(org.junit.Before) List(java.util.List) Login(nl.knaw.huygens.timbuctoo.security.dto.Login) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Login (nl.knaw.huygens.timbuctoo.security.dto.Login)6 LoginCreationException (nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException)4 Test (org.junit.Test)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Path (java.nio.file.Path)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 List (java.util.List)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)2 JsonBasedAuthenticatorStubs.backedByFile (nl.knaw.huygens.timbuctoo.security.JsonBasedAuthenticatorStubs.backedByFile)2 JsonBasedAuthenticatorStubs.throwingWithAlgorithm (nl.knaw.huygens.timbuctoo.security.JsonBasedAuthenticatorStubs.throwingWithAlgorithm)2 LocalLoginUnavailableException (nl.knaw.huygens.timbuctoo.security.exceptions.LocalLoginUnavailableException)2 FileHelpers (nl.knaw.huygens.timbuctoo.util.FileHelpers)2 CoreMatchers.not (org.hamcrest.CoreMatchers.not)2 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)2 Is.is (org.hamcrest.core.Is.is)2