public async Task NewPasswordIsInLastNPasswordsFails()
        {
            string username    = NeverExpiresUser.Username;
            string password    = NeverExpiresUser.Password;
            string domain      = NeverExpiresUser.Domain;
            string application = NeverExpiresUser.Application;
            AuthenticationResponse authResponse;
            var randomNumberGenerator = new Random();

            for (int i = 0; i < 4; i++)
            {
                authResponse = await CommonUtils.AuthenticateUser(username, password, domain, application);

                password += randomNumberGenerator.Next(1, 9).ToString();

                ChangePasswordRequest  changePasswordRequest  = ChangePasswordRequest.New(username, domain, application, authResponse.Jwt, password);
                ChangePasswordResponse changePasswordResponse = await APIs.ChangePasswordUserUrl.PostJsonAsync(changePasswordRequest).ReceiveJson <ChangePasswordResponse>();

                Assert.True(changePasswordResponse.Succeded);
            }

            authResponse = await CommonUtils.AuthenticateUser(username, password, domain, application);

            ChangePasswordRequest lastChangePasswordRequest = ChangePasswordRequest.New(username,
                                                                                        domain,
                                                                                        application,
                                                                                        authResponse.Jwt,
                                                                                        NeverExpiresUser.Password);

            try
            {
                ChangePasswordResponse lastChangePasswordResponse = await APIs.ChangePasswordUserUrl.PostJsonAsync(lastChangePasswordRequest).ReceiveJson <ChangePasswordResponse>();

                Assert.False(true, "Password Changed But Was Expected To Fail");
            }
            catch (FlurlHttpException exc)
            {
                var errorDetail = await exc.GetResponseJsonAsync <ProblemDetailResponse <ChangePasswordProblem> >();

                var changePwdErrorJson = Newtonsoft.Json.JsonConvert.SerializeObject(errorDetail, Newtonsoft.Json.Formatting.Indented);
                Assert.Equal("KS-E112", errorDetail.CustomProblem.ErrorCode);
                Assert.Contains("PV-E510", errorDetail.CustomProblem.CustomDataJson);
                Assert.False(errorDetail.CustomProblem.Succeded);
            }
        }
示例#2
0
        public async Task ChangePasswordWithJwtAfterPasswordExpiredSucceds()
        {
            var authResponse = await CommonUtils.AuthenticateUser(PasswordExpiredUser.Username,
                                                                  PasswordExpiredUser.Password,
                                                                  PasswordExpiredUser.Domain,
                                                                  PasswordExpiredUser.Application);

            Assert.False(authResponse.IsAuthenticated);
            Assert.NotEqual(authResponse.Jwt, string.Empty);


            ChangePasswordRequest changePasswordRequest = ChangePasswordRequest.New(PasswordExpiredUser.Username,
                                                                                    PasswordExpiredUser.Domain,
                                                                                    PasswordExpiredUser.Application,
                                                                                    authResponse.Jwt,
                                                                                    "prceLLINO616!");

            ChangePasswordResponse changePasswordResponse = await APIs.ChangePasswordUserUrl.PostJsonAsync(changePasswordRequest).ReceiveJson <ChangePasswordResponse>();

            Assert.Equal("KS-U002", changePasswordResponse.ResponseCode);
            Assert.True(changePasswordResponse.Succeded, changePasswordResponse.ResponseMessage);
        }
示例#3
0
        public static async Task <ChangePasswordResponse> ChangePassword(string user, string oldPassword, string newPassword, string domain, string app)
        {
            var authResponse = await AuthenticateUser(user, oldPassword, domain, app);

            CheckResponse(authResponse);
            ChangePasswordRequest changePasswordRequest = ChangePasswordRequest.New(user,
                                                                                    domain,
                                                                                    app,
                                                                                    authResponse.Jwt,
                                                                                    newPassword);

            try
            {
                ChangePasswordResponse changePasswordResponse = await APIs.ChangePasswordUserUrl.PostJsonAsync(changePasswordRequest).ReceiveJson <ChangePasswordResponse>();

                var changePwdJson = Newtonsoft.Json.JsonConvert.SerializeObject(changePasswordResponse, Newtonsoft.Json.Formatting.Indented);
                return(changePasswordResponse);
            }
            catch (FlurlHttpException exc)
            {
                var errorDetail = await exc.GetResponseJsonAsync <ProblemDetailResponse <ChangePasswordProblem> >();

                var changePwdErrorJson = Newtonsoft.Json.JsonConvert.SerializeObject(errorDetail, Newtonsoft.Json.Formatting.Indented);
                ChangePasswordResponse errorResponse =
                    new ChangePasswordResponse
                    (
                        responseId: errorDetail.ProblemDetailId,
                        correlationId: errorDetail.CorrelationId,
                        succeded: errorDetail.CustomProblem.Succeded,
                        responseCode: errorDetail.CustomProblem.ErrorCode,
                        responseMessage: errorDetail.Detail,
                        customDataJson: errorDetail.CustomProblem.CustomDataJson
                    );
                return(errorResponse);
            }
        }