-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Move UserTest.java to the new testsuite #39805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3b55c86 to
eb1e156
Compare
|
@lhanusov FYI the FIPS failures are unrelated to this PR. It happened in other runs as well. It seems it is now passing. I wanted to restart the tests but it seems there are other failures that may be related so I did not do it. |
65ab1ca to
822d4cf
Compare
test-framework/core/src/main/java/org/keycloak/testframework/events/AdminEventAssertion.java
Outdated
Show resolved
Hide resolved
test-framework/core/src/main/java/org/keycloak/testframework/realm/UserConfigBuilder.java
Outdated
Show resolved
Hide resolved
...viders/src/main/java/org/keycloak/testframework/remote/providers/runonserver/RunHelpers.java
Show resolved
Hide resolved
test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/AbstractPage.java
Show resolved
Hide resolved
test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/AbstractPage.java
Outdated
Show resolved
Hide resolved
test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/ErrorPage.java
Outdated
Show resolved
Hide resolved
test-framework/ui/src/main/java/org/keycloak/testframework/ui/util/PageUtils.java
Outdated
Show resolved
Hide resolved
tests/utils-shared/src/main/java/org/keycloak/testsuite/util/webdriver/PageUtils.java
Show resolved
Hide resolved
...tegration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AbstractPage.java
Outdated
Show resolved
Hide resolved
|
@stianst I've changed the pages stuff and other things, but still there are some questionable, please take a look, thanks |
| UserModel user = session.users().getUserByUsername(realm, username); | ||
| List<CredentialModel> storedCredentialsByType = user.credentialManager().getStoredCredentialsByTypeStream(CredentialRepresentation.PASSWORD) | ||
| .collect(Collectors.toList()); | ||
| System.out.println(storedCredentialsByType.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this print statement intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vaceksimon this was already there, I can remove it wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this, it seems to me that it was forgotten after a debugging session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
| } else if (expectedResourcePath.length == 1) { | ||
| Assertions.assertEquals(expectedResourcePath[0], event.getResourcePath()); | ||
| } else { | ||
| Assertions.assertEquals(String.join("/", expectedResourcePath), event.getResourcePath()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there is one parameter, doesn't String.join return just the same string?
String.join("/", "myString") // returns "myString"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. The issue is with the null parameters. According to Java, String.join("/", new String[] {"a", null, "a"}); is "a/null/a" 😄
What you can do is, instead of
AdminEventAssertion.assertEvent(adminEvents.poll(), OperationType.UPDATE, null, rep, ResourceType.REALM);use
AdminEventAssertion.assertSuccess(adminEvents.poll())
.operationType(OperationType.UPDATE)
.representation(rep)
.resourceType(ResourceType.REALM);to avoid the null value in the AbstractUserTest methods. That should solve the problem, and this method can stay unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the suggestion 👍
| } | ||
|
|
||
| @Test | ||
| public void createUserWithTempolaryCredentials() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public void createUserWithTempolaryCredentials() { | |
| public void createUserWithTemporaryCredentials() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, thanks
|
|
||
| @Test | ||
| public void testGetAndMoveCredentials() { | ||
| UserResource user = ApiUtil.findUserByUsernameId(managedRealm.admin(), userOtp2.getUsername()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this would be faster?
| UserResource user = ApiUtil.findUserByUsernameId(managedRealm.admin(), userOtp2.getUsername()); | |
| UserResource user = userOtp2.admin(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
| addFederatedIdentity(id, "social-provider-id", link); | ||
|
|
||
| // Verify social link is here | ||
| user = managedRealm.admin().users().get(id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to get the UserResource here again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
| assertTrue(user.toRepresentation().getRequiredActions().isEmpty()); | ||
|
|
||
| UserRepresentation userRep = user.toRepresentation(); | ||
| userRep.getRequiredActions().add("UPDATE_PASSWORD"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange that we use a hardcoded "UPDATE_PASSWORD" action here and also in other tests. Do we have a constant somewhere, or maybe use UserModel.RequiredAction.UPDATE_PASSWORD.toString() like in the last test method testDefaultRequiredActionAdded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
| WebApplicationException ex = assertThrows(WebApplicationException.class, () -> createUser(userRep2)); | ||
| assertThat(ex.getResponse().getStatusInfo().getStatusCode(), equalTo(400)); | ||
| assertThat(ex.getResponse().readEntity(ErrorRepresentation.class).getErrorMessage(), equalTo("error-invalid-length")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of rewriting ApiUtil#getCreatedId to throw WebApplicationException, I'd change this and similar statements to this:
| WebApplicationException ex = assertThrows(WebApplicationException.class, () -> createUser(userRep2)); | |
| assertThat(ex.getResponse().getStatusInfo().getStatusCode(), equalTo(400)); | |
| assertThat(ex.getResponse().readEntity(ErrorRepresentation.class).getErrorMessage(), equalTo("error-invalid-length")); | |
| Response response = managedRealm.admin().users().create(userRep2); | |
| assertThat(response.getStatus(), equalTo(400)); | |
| assertThat(response.readEntity(ErrorRepresentation.class).getErrorMessage(), equalTo("error-invalid-length")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice proposal, thanks :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file used? I don't see it anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed, thanks
| import jakarta.ws.rs.BadRequestException; | ||
| import jakarta.ws.rs.ClientErrorException; | ||
| import jakarta.ws.rs.NotFoundException; | ||
| import org.junit.Assert; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a forgotten JUnit4 Assert import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, thanks
f303600 to
f00d7ca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreported flaky test detected, please review
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.forms.BruteForceTest#testExceedMaxTemporaryLockouts |
| if (rep.getCredentials() == null) { | ||
| rep.setCredentials(new LinkedList<>()); | ||
| } | ||
|
|
||
| rep.getCredentials().add(credential); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Collections.combine like how it's done for passwords:
keycloak/test-framework/core/src/main/java/org/keycloak/testframework/realm/UserConfigBuilder.java
Lines 60 to 63 in 5e805ac
| public UserConfigBuilder password(String password) { | |
| rep.setCredentials(Collections.combine(rep.getCredentials(), Representations.toCredential(CredentialRepresentation.PASSWORD, password))); | |
| return this; | |
| } |
| } | ||
|
|
||
| public UserConfigBuilder federatedLink(String identityProvider, String federatedUserId, String federatedUsername) { | ||
| if (rep.getFederatedIdentities() == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Collections.combine instead like mentioned below for totpSecret
|
|
||
| public void assertCurrent() { | ||
| String name = getClass().getSimpleName(); | ||
| Assertions.assertTrue(isActivePage(), "Expected " + name + " but was " + driver.getTitle() + " (" + driver.getCurrentUrl() + ")"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just use the data-page-id stuff in the message here as well. Perhaps:
Assertions.assertTrue(isActivePage(), "Expected " + getExpectedPageId() + " but was " + getCurrentPageId());
Or, maybe this is even better:
Assertions.assertEquals(getExpectedPageId(), getCurrentPageId(), "Not on expected page");
| return body.getAttribute("data-page-id"); | ||
| } | ||
|
|
||
| public String getPageTitle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the usage of getPageTitle it's asserting that it's on a specific page, so perhaps just do loginPage.assertCurrent() instead in the test of asserting the page title?
| : null; | ||
| } | ||
|
|
||
| public void clickToContinueDe() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is horrible; is there no id set on the link that we can use instead of looking up the link based on link-text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:-D, I've just copy/pasted what was already there, I will check the id instead and come back with a new solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to remove those unused links. It will be added once those tests are migrated.
ffc9c7f to
594864c
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.federation.ldap.LDAPReadOnlyTest#testReadOnlyUserGetsPermanentlyLocked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreported flaky test detected, please review
Part of: keycloak#34494 Signed-off-by: Lukas Hanusovsky <[email protected]>
Part of: #34494