Ensure transaction is rolled back upon error#19488
Merged
hmlnarik merged 2 commits intokeycloak:mainfrom Apr 3, 2023
Merged
Conversation
ceba687 to
b6b8b97
Compare
mposolda
approved these changes
Apr 3, 2023
Contributor
|
@hmlnarik Thanks for the fix! LGTM as long as tests are OK |
Contributor
|
@hmlnarik @mposolda is this included in the latest nightly docker image? I've tried to migrate my test from my previous MR ( #17646 ) just to be sure, but:
The test I try to run: @Test
public void testRegisterShouldFailBeforeUserCreationWhenUserIsInContext() throws Exception {
try (AutoCloseable c = new RealmAttributeUpdater(testRealmResource())
.updateWith(r -> {
Map<String, String> config = new HashMap<>();
config.put("from", "[email protected]");
config.put("host", "localhost");
config.put("port", "3025");
r.setSmtpServer(config);
r.setRegistrationAllowed(true);
r.setVerifyEmail(true);
r.setResetPasswordAllowed(true);
r.setRegistrationEmailAsUsername(true);
})
.update()) {
UserRepresentation userWhoPreExistsInRealm = new UserRepresentation();
userWhoPreExistsInRealm.setEmail("[email protected]");
ApiUtil.createUserAndResetPasswordWithAdminClient(testRealmResource(), userWhoPreExistsInRealm, "password");
testRealmAccountPage.navigateTo();
loginPage.clickRegister();
registerPage.clickBackToLogin();
loginPage.assertCurrent(testRealmResource().toRepresentation().getRealm());
loginPage.resetPassword();
resetPage.assertCurrent();
resetPage.changePassword("[email protected]");
driver.navigate().back();
driver.navigate().back();
driver.navigate().back();
registerPage.assertCurrent();
registerPage.registerWithEmailAsUsername(
"Vilmos",
"Szabó-Nagy",
"[email protected]",
"TestPassword123",
"TestPassword123"
);
errorPage.assertCurrent();
assertEquals("The error page is shown", "Invalid username or password.", errorPage.getError()); // it does not fail here, the error page is shown
// the user entity should not be created if the registration flow is not executed till the end
final UserRepresentation userByUsername = ApiUtil.findUserByUsername(testRealmResource(), "[email protected]");
assertNull(userByUsername); // it fails here
}
}The git commit which I run the test: And I'm still able to reproduce my error on the latest nightly docker image, this one: https://quay.io/repository/keycloak/keycloak/manifest/sha256:1fa2e183aa62f223724a827d07a5023141ae6eb6d4d1319f39d6fa5228aea206 |
Contributor
|
I've created the #19556 PR to demonstrate the failing test case. |
2 tasks
vilmosnagy
added a commit
to vilmosnagy/keycloak
that referenced
this pull request
Aug 30, 2023
registration Adding a failing test from keycloak#17644. The keycloak#19488 PR seems not to solve it
mposolda
pushed a commit
to mposolda/keycloak
that referenced
this pull request
Sep 7, 2023
registration Adding a failing test from keycloak#17644. The keycloak#19488 PR seems not to solve it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change ensures that an exception is thrown from endpoints upon error rather than returning a valid response which would commit an transaction that could have recorded changes to an object. Thrown transaction then sets the code to rollback. To ensure that events are recorded in the case of error, errors are recorded in separate transaction.
This has revealed an issue in the client policy test, which has been fixed by the second commit.
Closes: #17644
Closes: #19487