use of org.wso2.carbon.identity.recovery.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()]);
}
use of org.wso2.carbon.identity.recovery.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());
}
use of org.wso2.carbon.identity.recovery.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);
}
use of org.wso2.carbon.identity.recovery.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);
}
use of org.wso2.carbon.identity.recovery.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);
}
Aggregations