Search in sources :

Example 16 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project identity-governance by wso2-extensions.

the class Utils method getDefaultChallengeQuestions.

public static ChallengeQuestion[] getDefaultChallengeQuestions() {
    List<ChallengeQuestion> challengeQuestions = new ArrayList<>();
    // locale en_US, challengeSet1
    int count = 0;
    for (String question : IdentityRecoveryConstants.Questions.SECRET_QUESTIONS_SET01) {
        String setId = IdentityRecoveryConstants.WSO2CARBON_CLAIM_DIALECT + "/" + "challengeQuestion1";
        String questionId = "question" + (++count);
        challengeQuestions.add(new ChallengeQuestion(setId, questionId, question, IdentityRecoveryConstants.LOCALE_EN_US));
    }
    count = 0;
    for (String question : IdentityRecoveryConstants.Questions.SECRET_QUESTIONS_SET02) {
        String setId = IdentityRecoveryConstants.WSO2CARBON_CLAIM_DIALECT + "/" + "challengeQuestion2";
        String questionId = "question" + (++count);
        challengeQuestions.add(new ChallengeQuestion(setId, questionId, question, IdentityRecoveryConstants.LOCALE_EN_US));
    }
    return challengeQuestions.toArray(new ChallengeQuestion[challengeQuestions.size()]);
}
Also used : ArrayList(java.util.ArrayList) ChallengeQuestion(org.wso2.carbon.identity.recovery.model.ChallengeQuestion)

Example 17 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project product-is by wso2.

the class ChallengeQuestionManagementAdminServiceTestCase method getDefaultChallengeQuestionsForUser.

@Test(groups = "wso2.is", description = "Get default questions if the locale doesn't have any questions set.", priority = 7, sequential = true)
public void getDefaultChallengeQuestionsForUser() throws Exception {
    challengeQuestionsAdminClient = new ChallengeQuestionMgtAdminClient(backendURL, BOB_USERNAME, BOB_PASSWORD);
    User bob = new User();
    bob.setUserName(BOB_USERNAME);
    bob.setTenantDomain(SUPER_TENANT);
    // we need to confirm there are no challenge questions in Bob's locale
    ChallengeQuestion[] localeQuestions = challengeQuestionsAdminClient.getChallengeQuestionsForLocale(SUPER_TENANT, BOB_LOCALE);
    int bobLocale = localeQuestions == null ? 0 : localeQuestions.length;
    assertTrue(bobLocale == 0, "Cannot have challenge questions in " + BOB_LOCALE);
    // this should return us with default questions since Bob's locale doesn't have any challenge questions.
    int count = challengeQuestionsAdminClient.getChallengeQuestionsForUser(bob).length;
    assertTrue(count > 1, "Default Challenge Questions not retrieved for user : " + bob.toString());
}
Also used : User(org.wso2.carbon.identity.application.common.model.xsd.User) ChallengeQuestionMgtAdminClient(org.wso2.identity.integration.common.clients.challenge.questions.mgt.ChallengeQuestionMgtAdminClient) ChallengeQuestion(org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 18 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project product-is by wso2.

the class ChallengeQuestionManagementAdminServiceTestCase method deleteChallengeQuestionsByLocale.

@Test(groups = "wso2.is", description = "Deleting challenge question in a locale", priority = 6, sequential = true)
public void deleteChallengeQuestionsByLocale() throws Exception {
    challengeQuestionsAdminClient = new ChallengeQuestionMgtAdminClient(backendURL, isServer.getSuperTenant().getTenantAdmin().getUserName(), isServer.getSuperTenant().getTenantAdmin().getUserName());
    // get challenge challenge questions of xx_YY locale
    ChallengeQuestion[] challengeQuestions = challengeQuestionsAdminClient.getChallengeQuestionsForLocale(SUPER_TENANT, BOB_LOCALE);
    // we should have challenge questions in the locale by now.
    assertTrue(challengeQuestions != null && challengeQuestions.length > 0);
    // delete all the challenge questions in the xx_YY locale
    challengeQuestionsAdminClient.deleteChallengeQuestions(challengeQuestions, SUPER_TENANT);
    // delete all added challenge questions in the en_US locale
    challengeQuestionsAdminClient.deleteChallengeQuestions(new ChallengeQuestion[] { challengeQuestionSet1 }, SUPER_TENANT);
    // retrieve challenge questions once again.
    challengeQuestions = challengeQuestionsAdminClient.getChallengeQuestionsForLocale(SUPER_TENANT, BOB_LOCALE);
    int numberOfQuestions = challengeQuestions == null ? 0 : challengeQuestions.length;
    // now we shouldn't have challenge questions.
    assertTrue(numberOfQuestions == 0);
}
Also used : ChallengeQuestionMgtAdminClient(org.wso2.identity.integration.common.clients.challenge.questions.mgt.ChallengeQuestionMgtAdminClient) ChallengeQuestion(org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 19 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project product-is by wso2.

the class ChallengeQuestionManagementAdminServiceTestCase method addChallengeQuestionByTenant.

@Test(groups = "wso2.is", description = "Getting challenge questions of a user", priority = 2, sequential = true)
public void addChallengeQuestionByTenant() throws Exception {
    int countBefore = challengeQuestionsBobClient.getChallengeQuestionsForTenant(SUPER_TENANT).length;
    challengeQuestionSet1 = new ChallengeQuestion();
    challengeQuestionSet1.setQuestionSetId("newSet1");
    challengeQuestionSet1.setQuestionId("q1");
    challengeQuestionSet1.setQuestion("This is a new Challenge Question????");
    challengeQuestionSet1.setLocale("en_US");
    challengeQuestionsBobClient.setChallengeQuestions(new ChallengeQuestion[] { challengeQuestionSet1 }, SUPER_TENANT);
    int countAfter = challengeQuestionsBobClient.getChallengeQuestionsForTenant(SUPER_TENANT).length;
    assertTrue(countBefore + 1 == countAfter, "Adding a new challenge question failed in " + SUPER_TENANT);
}
Also used : ChallengeQuestion(org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 20 with ChallengeQuestion

use of org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion in project product-is by wso2.

the class ServerChallengeTestCase method updateChallengeQuestionPATCHTest.

/**
 * This test method validate update challenge question api response.
 *
 * @throws JSONException thrown to indicate a problem with the JSON.
 */
@Test(dependsOnMethods = { "addsNewChallengeQuestionSetTest" })
public void updateChallengeQuestionPATCHTest() throws JSONException {
    String operation = "add";
    String locale = "en_US";
    String questionID = "question6";
    String challengeQuestion = "What is the name of your first school?";
    ServerChallengeModel.Questions question = new ServerChallengeModel.Questions(locale, challengeQuestion, questionID);
    ServerChallengeModel.ChallengeQuestionOperation challengeQuestionOperation = new ServerChallengeModel.ChallengeQuestionOperation(question, operation);
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(challengeQuestionOperation);
    given().auth().preemptive().basic(USER_NAME, PASSWORD).contentType(ContentType.JSON).header(HttpHeaders.ACCEPT, ContentType.JSON).body(json).log().ifValidationFails().when().patch(RESOURCE_PATH + "/{challenge-set-id}", QUESTION_SET_ID).then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_CREATED).log().ifValidationFails();
    getsChallengeQuestionTest(QUESTION_SET_ID, challengeQuestion, questionID);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ServerChallengeModel(org.wso2.identity.integration.test.rest.api.server.challenge.v1.model.ServerChallengeModel) Gson(com.google.gson.Gson) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ChallengeQuestion (org.wso2.carbon.identity.recovery.model.ChallengeQuestion)26 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)8 IdentityRecoveryException (org.wso2.carbon.identity.recovery.IdentityRecoveryException)8 UserChallengeAnswer (org.wso2.carbon.identity.recovery.model.UserChallengeAnswer)7 ChallengeQuestion (org.wso2.carbon.identity.recovery.stub.model.ChallengeQuestion)6 UserStoreException (org.wso2.carbon.user.api.UserStoreException)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 IdentityRecoveryClientException (org.wso2.carbon.identity.recovery.IdentityRecoveryClientException)5 IdentityException (org.wso2.carbon.identity.base.IdentityException)3 ChallengeQuestionManager (org.wso2.carbon.identity.recovery.ChallengeQuestionManager)3 ChallengeQuestionResponse (org.wso2.carbon.identity.recovery.bean.ChallengeQuestionResponse)3 UserRecoveryData (org.wso2.carbon.identity.recovery.model.UserRecoveryData)3 UserRecoveryDataStore (org.wso2.carbon.identity.recovery.store.UserRecoveryDataStore)3 ChallengeQuestionDTO (org.wso2.carbon.identity.rest.api.server.challenge.v1.dto.ChallengeQuestionDTO)3 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 Map (java.util.Map)2