Search in sources :

Example 1 with BasicAuthValidator

use of org.nhindirect.common.rest.auth.BasicAuthValidator in project nhin-d by DirectProject.

the class HashableBasicAuthValidator_authenticateRawTest method testAuthenticate_unknownUser_assertAssertException.

@Test
public void testAuthenticate_unknownUser_assertAssertException() throws Exception {
    BasicAuthValidator validator = buildValidator();
    boolean exceptionOccured = false;
    try {
        final String rawAuth = buildRawCredential("test", "password");
        validator.authenticate(rawAuth);
    } catch (NoSuchUserException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) NoSuchUserException(org.nhindirect.common.rest.auth.exceptions.NoSuchUserException) Test(org.junit.Test)

Example 2 with BasicAuthValidator

use of org.nhindirect.common.rest.auth.BasicAuthValidator in project nhin-d by DirectProject.

the class HashableBasicAuthValidator_authenticateTest method testAuthenticate_unknownUser_assertAssertException.

@Test
public void testAuthenticate_unknownUser_assertAssertException() throws Exception {
    BasicAuthValidator validator = buildValidator();
    boolean exceptionOccured = false;
    try {
        validator.authenticate("test", "password");
    } catch (NoSuchUserException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) NoSuchUserException(org.nhindirect.common.rest.auth.exceptions.NoSuchUserException) Test(org.junit.Test)

Example 3 with BasicAuthValidator

use of org.nhindirect.common.rest.auth.BasicAuthValidator in project nhin-d by DirectProject.

the class HashableBasicAuthValidator_authenticateTest method testAuthenticate_invalidAlg_assertAssertException.

@Test
public void testAuthenticate_invalidAlg_assertAssertException() throws Exception {
    BasicAuthValidator validator = buildValidator();
    HashableBasicAuthValidator.DIGEST_TYPE_MAP.put("Bogus", "Bogus");
    ((HashableBasicAuthValidator) validator).hashType = "Bogus";
    boolean exceptionOccured = false;
    try {
        validator.authenticate("gm2552", "Password");
    } catch (BasicAuthException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
    HashableBasicAuthValidator.DIGEST_TYPE_MAP.remove("Bogus");
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) BasicAuthException(org.nhindirect.common.rest.auth.exceptions.BasicAuthException) Test(org.junit.Test)

Example 4 with BasicAuthValidator

use of org.nhindirect.common.rest.auth.BasicAuthValidator in project nhin-d by DirectProject.

the class HashableBasicAuthValidator_authenticateRawTest method testAuthenticate_validCredentials_assertPrinciple.

@Test
public void testAuthenticate_validCredentials_assertPrinciple() throws Exception {
    BasicAuthValidator validator = buildValidator();
    final String rawAuth = buildRawCredential("gm2552", "password");
    NHINDPrincipal prin = validator.authenticate(rawAuth);
    assertEquals("gm2552", prin.getName());
    assertEquals("admin", prin.getRole());
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) NHINDPrincipal(org.nhindirect.common.rest.auth.NHINDPrincipal) Test(org.junit.Test)

Example 5 with BasicAuthValidator

use of org.nhindirect.common.rest.auth.BasicAuthValidator in project nhin-d by DirectProject.

the class HashableBasicAuthValidator_authenticateRawTest method testAuthenticate_invalidCreds_assertAssertException.

@Test
public void testAuthenticate_invalidCreds_assertAssertException() throws Exception {
    BasicAuthValidator validator = buildValidator();
    boolean exceptionOccured = false;
    try {
        final String rawAuth = buildRawCredential("gm2552", "Password");
        validator.authenticate(rawAuth);
    } catch (BasicAuthException e) {
        exceptionOccured = true;
    }
    assertTrue(exceptionOccured);
}
Also used : BasicAuthValidator(org.nhindirect.common.rest.auth.BasicAuthValidator) BasicAuthException(org.nhindirect.common.rest.auth.exceptions.BasicAuthException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 BasicAuthValidator (org.nhindirect.common.rest.auth.BasicAuthValidator)7 BasicAuthException (org.nhindirect.common.rest.auth.exceptions.BasicAuthException)3 NHINDPrincipal (org.nhindirect.common.rest.auth.NHINDPrincipal)2 NoSuchUserException (org.nhindirect.common.rest.auth.exceptions.NoSuchUserException)2