Search in sources :

Example 21 with User

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();
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) ObjectContext(org.apache.cayenne.ObjectContext) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 22 with User

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();
}
Also used : User(org.haiku.haikudepotserver.dataobjects.User) AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) ObjectContext(org.apache.cayenne.ObjectContext) SignedJWT(com.nimbusds.jwt.SignedJWT) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 23 with User

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());
}
Also used : Captcha(org.haiku.haikudepotserver.captcha.model.Captcha) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext) ChangePasswordRequest(org.haiku.haikudepotserver.api1.model.user.ChangePasswordRequest) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with User

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();
    }
}
Also used : AuthenticateUserRequest(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext) SignedJWT(com.nimbusds.jwt.SignedJWT) AuthenticateUserResult(org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 25 with User

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();
}
Also used : UserRating(org.haiku.haikudepotserver.dataobjects.UserRating) User(org.haiku.haikudepotserver.dataobjects.User) ObjectContext(org.apache.cayenne.ObjectContext)

Aggregations

User (org.haiku.haikudepotserver.dataobjects.User)51 ObjectContext (org.apache.cayenne.ObjectContext)47 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)16 Test (org.junit.jupiter.api.Test)16 AccessDeniedException (org.springframework.security.access.AccessDeniedException)14 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)7 ObjectId (org.apache.cayenne.ObjectId)5 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)5 org.haiku.haikudepotserver.dataobjects.auto._User (org.haiku.haikudepotserver.dataobjects.auto._User)5 PermissionUserPkg (org.haiku.haikudepotserver.dataobjects.PermissionUserPkg)4 AuthenticateUserRequest (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserRequest)3 AuthenticateUserResult (org.haiku.haikudepotserver.api1.model.user.AuthenticateUserResult)3 Captcha (org.haiku.haikudepotserver.captcha.model.Captcha)3 Preconditions (com.google.common.base.Preconditions)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 CSVWriter (com.opencsv.CSVWriter)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Instant (java.time.Instant)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2