Search in sources :

Example 11 with ChaiValidationException

use of com.novell.ldapchai.exception.ChaiValidationException in project ldapchai by ldapchai.

the class ChaiTester method testChaiResponseSet.

public void testChaiResponseSet() throws Exception {
    final ChaiEntry testContainer = TestHelper.createTestContainer();
    final ChaiUser testUser;
    final ChaiConfiguration chaiConfig = new ChaiConfiguration("ldaps://ldaphost:636", "cn=admin,ou=ou,o=o", "password");
    {
        // create provider and test user.
        chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
        final ChaiProvider provider = ChaiProviderFactory.createProvider(chaiConfig);
        testUser = ChaiUtility.createUser("cn=responseTestUser," + testContainer.getEntryDN(), "sn", provider);
    }
    // create challenges/responses
    final Map<Challenge, String> crMap;
    {
        final Map<Challenge, String> tempMap = new HashMap<Challenge, String>();
        tempMap.put(new ChaiChallenge(true, "c1", 5, 200, true), "response1");
        tempMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response2");
        tempMap.put(new ChaiChallenge(false, "c3", 5, 200, true), "response3");
        tempMap.put(new ChaiChallenge(false, "c4", 5, 200, true), "response4");
        crMap = Collections.unmodifiableMap(tempMap);
    }
    // write responses to user entry
    {
        final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(crMap, null, 0, chaiConfig, null);
        ChaiCrFactory.writeChaiResponseSet(responseSet, testUser);
    }
    // read responses from user entry
    final ResponseSet retreivedSet = ChaiCrFactory.readChaiResponseSet(testUser);
    Assert.assertTrue("error testing chai responses", retreivedSet.test(crMap));
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>(crMap);
        testMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response3");
        Assert.assertFalse("error testing chai responses, false positive", retreivedSet.test(testMap));
    }
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>(crMap);
        testMap.put(new ChaiChallenge(true, "c2", 50, 200, true), "response2");
        try {
            final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(testMap, null, 0, chaiConfig, null);
            ChaiCrFactory.writeChaiResponseSet(responseSet, testUser);
            Assert.fail("did not throw expected IllegalArgumentException due to response length being to short");
        } catch (ChaiValidationException e) {
        /* test should throw exception */
        }
    }
    {
        final ResponseSet testRs = ChaiCrFactory.newChaiResponseSet(crMap, null, 1, chaiConfig, null);
        final ChallengeSet testCs = new ChaiChallengeSet(crMap.keySet(), 1, null, null);
        Assert.assertTrue("meetsChallengeSetRequirements failed positive test", testRs.meetsChallengeSetRequirements(testCs));
    }
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>();
        testMap.put(new ChaiChallenge(true, "c1", 5, 200, true), "response1");
        testMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response2");
        final ResponseSet testRs = ChaiCrFactory.newChaiResponseSet(testMap, null, 1, chaiConfig, null);
        final ChallengeSet testCs = new ChaiChallengeSet(crMap.keySet(), 2, null, null);
        try {
            testRs.meetsChallengeSetRequirements(testCs);
            Assert.fail("meetsChallengeSetRequirements failed positive test");
        } catch (ChaiValidationException e) {
        /* test should throw exception */
        }
    }
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) NmasResponseSet(com.novell.ldapchai.impl.edir.NmasResponseSet) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider)

Aggregations

ChaiValidationException (com.novell.ldapchai.exception.ChaiValidationException)11 ErrorInformation (password.pwm.error.ErrorInformation)8 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)5 Challenge (com.novell.ldapchai.cr.Challenge)4 ResponseSet (com.novell.ldapchai.cr.ResponseSet)4 ChaiChallenge (com.novell.ldapchai.cr.ChaiChallenge)3 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)3 ArrayList (java.util.ArrayList)3 PwmOperationalException (password.pwm.error.PwmOperationalException)3 ChaiUser (com.novell.ldapchai.ChaiUser)2 ChaiChallengeSet (com.novell.ldapchai.cr.ChaiChallengeSet)2 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)2 ChallengeSet (com.novell.ldapchai.cr.ChallengeSet)2 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)2 ResponseInfoBean (password.pwm.bean.ResponseInfoBean)2 ChaiEntry (com.novell.ldapchai.ChaiEntry)1 Answer (com.novell.ldapchai.cr.Answer)1 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)1 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)1