Skip to content
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

[ELY-2411] Add test cases to MappedRegexRealmMapperTest #1756

Conversation

xjusko
Copy link
Contributor

@xjusko xjusko commented Sep 14, 2022

realmNameMap.put("A-9999", realmName);
realmNameMap.put("A-1111", "delegateRealm");
MappedRegexRealmMapper mappedRegexRealmMapper = new MappedRegexRealmMapper(pattern, RealmMapper.single("A-1111"), realmNameMap);
Principal principal = new NamePrincipal("A-9999");
Copy link
Contributor

@Skyllarr Skyllarr Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xjusko Thank you very much for the PR and sorry for the late response.

This looks good, only this second test class does not actually makes use of the delegate realm. You can see that if you delete the RealmMapper.single("A-1111") from the constructor on line 85 and the test will still pass.

To make this test use the delegate realm, we have to use a principal that does not match the pattern, eg:

new NamePrincipal("principalThatDoesNotMatchThePattern");

Then the delegate realm will be used and the result of the delegate will be a realm A-1111. This realm will then be processed by realmNameMap which will find the mapping defined above:

realmNameMap.put("A-1111", "delegateRealm");

The resulting realm will then be "delegateRealm". So the line 85 should be:

Assert.assertEquals("delegateRealm", mappedRegexRealmMapper.getRealmMapping(principal, null));

If you update the PR accordingly it will be accepted. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Skyllarr I think my intention was to write a test to determine whether it returns realmName or "delegateRealm" when both match. However, now I am not sure whether that was the correct implementation of my idea. If I update it as you mentioned, then both tests would test the same thing, which we probably do not want. If this test does not make sense, maybe it would be better to remove it and keep only the first one. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xjusko I see, sorry I misunderstood your intention. I think this test is good then. I am approving this PR. Thank you!

@Skyllarr Skyllarr added the +1 DV label Oct 20, 2022
Copy link
Contributor

@fjuma fjuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xjusko!

@fjuma fjuma merged commit 17b620a into wildfly-security:1.x Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants