use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_fail.
@Test
public void testAuthenticateUser_fail() {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "y63j20f22"));
// ------------------------------------
Assertions.assertThat(result.token).isNull();
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_succcessWithAgreement.
@Test
public void testAuthenticateUser_succcessWithAgreement() throws Exception {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
integrationTestSupportService.agreeToUserUsageConditions(context, user);
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "U7vqpsu6BB"));
// ------------------------------------
Assertions.assertThat(result.token).isNotNull();
Assertions.assertThat(userAuthenticationService.authenticateByToken(result.token).isPresent()).isTrue();
SignedJWT signedJWT = SignedJWT.parse(result.token);
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
Assertions.assertThat(signedJWT.getJWTClaimsSet().getSubject()).isEqualTo("testuser@hds");
// because the user has agreed to the usage conditions they will not get
// this flag in the response JWT token.
Assertions.assertThat(claims.get("ucnd")).isNull();
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testChangePassword.
@Test
public void testChangePassword() {
Captcha captcha = captchaService.generate();
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
setAuthenticatedUser("testuser");
// check that the password is correctly configured.
Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "U7vqpsu6BB").get()).isEqualTo(user.getObjectId());
// now change it.
ChangePasswordRequest request = new ChangePasswordRequest();
request.nickname = "testuser";
request.captchaResponse = captcha.getResponse();
request.captchaToken = captcha.getToken();
request.newPasswordClear = "8R3nlp11gX";
request.oldPasswordClear = "U7vqpsu6BB";
// ------------------------------------
userApi.changePassword(request);
// ------------------------------------
// now check that the old authentication no longer works and the new one does work
Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "U7vqpsu6BB").isPresent()).isFalse();
Assertions.assertThat(userAuthenticationService.authenticateByNicknameAndPassword("testuser", "8R3nlp11gX").get()).isEqualTo(user.getObjectId());
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserApiIT method testAuthenticateUser_succcessNoAgreement.
@Test
public void testAuthenticateUser_succcessNoAgreement() throws Exception {
ObjectContext context = serverRuntime.newContext();
integrationTestSupportService.createBasicUser(context, "testuser", "U7vqpsu6BB");
setAuthenticatedUser("testuser");
// ------------------------------------
AuthenticateUserResult result = userApi.authenticateUser(new AuthenticateUserRequest("testuser", "U7vqpsu6BB"));
// ------------------------------------
Assertions.assertThat(result.token).isNotNull();
Assertions.assertThat(userAuthenticationService.authenticateByToken(result.token).isPresent()).isTrue();
SignedJWT signedJWT = SignedJWT.parse(result.token);
Map<String, Object> claims = signedJWT.getJWTClaimsSet().getClaims();
Assertions.assertThat(signedJWT.getJWTClaimsSet().getSubject()).isEqualTo("testuser@hds");
// because the user has not agreed to the usage conditions they will get
// this flag come up in their token.
Assertions.assertThat(claims.get("ucnd")).isEqualTo(Boolean.TRUE);
{
User userAfter = User.getByNickname(context, "testuser");
Assertions.assertThat(userAfter.getLastAuthenticationTimestamp()).isNotNull();
}
}
use of org.haiku.haikudepotserver.dataobjects.User in project haikudepotserver by haiku.
the class UserRatingApiIT method createTestUserAndSampleUserRating.
private String createTestUserAndSampleUserRating() {
ObjectContext context = serverRuntime.newContext();
User user = integrationTestSupportService.createBasicUser(context, "testuser", "password");
integrationTestSupportService.agreeToUserUsageConditions(context, user);
UserRating userRating = context.newObject(UserRating.class);
userRating.setNaturalLanguage(NaturalLanguage.getByCode(context, NaturalLanguage.CODE_SPANISH));
userRating.setComment("How now brown cow");
userRating.setPkgVersion(pkgService.getLatestPkgVersionForPkg(context, Pkg.tryGetByName(context, "pkg1").get(), Repository.tryGetByCode(context, "testrepo").get(), Collections.singletonList(Architecture.tryGetByCode(context, "x86_64").get())).get());
userRating.setRating((short) 3);
userRating.setUserRatingStability(UserRatingStability.getByCode(context, UserRatingStability.CODE_VERYUNSTABLE).get());
userRating.setUser(user);
context.commitChanges();
return userRating.getCode();
}
Aggregations