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

#913 #1066 ScopesAuthorizer refactoring #1478

Open
wants to merge 11 commits into
base: release/24.0
Choose a base branch
from

Conversation

mehyaa
Copy link

@mehyaa mehyaa commented May 31, 2021

Fixes #913 #1066

Scopes can be a space separated list in a single claim. Include this possibility on allowed scopes check.

Proposed Changes

  • Split user scope values with space character if scope claim is an single claim and its value has space character(s)
  • User scopes must have all allowed scopes

@mehyaa
Copy link
Author

mehyaa commented Jun 1, 2021

The build is broken, it fails on irrelevant part from this PR. #1436 fixes is I think.

@PatrickDelancy
Copy link

This is still an issue. Adding my 👍 to get this small and valuable PR merged.

@raman-m
Copy link
Member

raman-m commented Jun 30, 2023

Please do the following:

  • Merge PR 1
  • Rebase feature branch onto develop
  • Resolve all merge conflicts

@raman-m
Copy link
Member

raman-m commented Aug 18, 2023

Mehmet,
Thanks for resolving of merge conflicts!

Unfortunately the last build is failed: 5 acceptance tests have failed!

Why is your PR code so unstable?

@mehyaa
Copy link
Author

mehyaa commented Aug 18, 2023

I haven't found out the reason why the tests failed with a quick look. I couldn't figure out the tests structure. When I have time I'll look into it.

@raman-m
Copy link
Member

raman-m commented Aug 24, 2023

@mehyaa
The feature branch has been rebased onto ThreeMammals:develop successfully!
The build has failed with 5 tests!
Code review will start after fixing of these failed tests.
Also, some new tests should cover your proposed changes in the ScopesAuthorizer class.

Could you add me as collaborator to your forked repo please? I will fix develop branch because now it has the diff, but both develop branches should be identical.

@raman-m raman-m added bug Identified as a potential bug proposal Proposal for a new functionality in Ocelot needs feedback Issue is waiting on feedback before acceptance labels Aug 24, 2023
@raman-m raman-m added help wanted Not actively being worked on. If you plan to contribute, please drop a note. medium effort Likely a few days of development effort labels Aug 24, 2023
@mehyaa
Copy link
Author

mehyaa commented Sep 14, 2023

@raman-m I've fixed the tests. Failing tests were written for the bug that requires one of allowed scopes. I've changed the claims and allowed scopes on tests so they can test the correct conditions.

For adding new tests to test ScopesAuthorizer, the current tests seem pretty sufficient.

@mehyaa
Copy link
Author

mehyaa commented Sep 14, 2023

@raman-m I've added you as collaborator on my fork, you can fix the diff or guide me to how-to.

@mehyaa
Copy link
Author

mehyaa commented Sep 15, 2023

Interestingly some irrelevant tests fail irregularly.

@raman-m
Copy link
Member

raman-m commented Sep 15, 2023

@mehyaa commented on Sep 14, 11:38 AM

Thanks for fixing of failed tests!


For adding new tests to test ScopesAuthorizer, the current tests seem pretty sufficient.

No, at least one new test should cover claims logic having them multiple in the related config property.
Simultaneously, we should update current tests to be green. Because each test covers specific atomic feature.

Come on! We've changed the logic from single Scope to multiple ones! And it is definitely right time to cover these changes.

I have idea: let's write tests for each linked issue:

Sounds good?

@raman-m
Copy link
Member

raman-m commented Sep 15, 2023

@mehyaa commented on Sep 14, 11:42 AM

Thanks for adding me as collaborator!
Now your develop branch is up to date with ThreeMammals:develop. So, I've performed Sync fork operation.
Done!
You can start rebasing of current branches onto (creation of new ones from) your develop branch.

@raman-m
Copy link
Member

raman-m commented Sep 15, 2023

@mehyaa commented on Sep 15

Don't worry! This is unstable scenario: Ocelot.AcceptanceTests.ConfigurationReloadTests.should_reload_config_on_change
The next run fixes the build usually.
Truly speaking, I am tired of this test too. I will create bug issue soon for this test.

@raman-m raman-m changed the title ScopesAuthorizer refactoring #913 #1066 ScopesAuthorizer refactoring Sep 15, 2023
@raman-m
Copy link
Member

raman-m commented Jan 21, 2024

@mehyaa
Why not to continue working? Firstly resolving all merge conflicts and merging from develop...

@raman-m raman-m added 2023 Annual 2023 release Authorization Ocelot feature: Authorization and removed help wanted Not actively being worked on. If you plan to contribute, please drop a note. medium effort Likely a few days of development effort needs feedback Issue is waiting on feedback before acceptance labels Jan 21, 2024
@raman-m raman-m added this to the Annual 2023 milestone Mar 5, 2024
@raman-m raman-m changed the base branch from develop to release/24.0 March 5, 2024 10:03
@raman-m
Copy link
Member

raman-m commented Apr 16, 2024

Possible dependency

@raman-m
Copy link
Member

raman-m commented Apr 16, 2024

The branch has been rebased onto release/24.0 with top commit 59b63ea !

@raman-m raman-m self-assigned this Apr 16, 2024
@raman-m
Copy link
Member

raman-m commented Apr 16, 2024

@mehyaa Mehmet,
If you're no longer interested in your PR, please allow me to take it over. I will then deliver the feature with my own design vision.

Development is required❕

@raman-m
Copy link
Member

raman-m commented Apr 19, 2024

Failed acceptance test: Ocelot.AcceptanceTests.AuthorizationTests.should_return_response_200_using_identity_server_with_allowed_scope

@raman-m raman-m added the high High priority label Apr 19, 2024
var matchesScopes = routeAllowedScopes.Intersect(userScopes);

if (!matchesScopes.Any())
if (routeAllowedScopes.Any(s => !userScopes.Contains(s)))

Choose a reason for hiding this comment

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

Denial is more costly:

To make scope checking more efficient and less costly, a good practice is to invert the condition.

You can also use a method that minimizes the number of iterations required in the collections, making sure that all required scopes are present in the user scopes.

if (routeAllowedScopes.TrueForAll(userScopes.Contains))
{
    return new OkResponse<bool>(true);
}

return new ErrorResponse<bool>(
    new ScopeNotAuthorizedError($"User scopes: '{string.Join(",", userScopes)}' do not have all allowed scopes: '{string.Join(",", routeAllowedScopes)}'"));

Copy link
Member

Choose a reason for hiding this comment

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

Right! Thanks!
It makes sense to invert the condition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2023 Annual 2023 release Authorization Ocelot feature: Authorization bug Identified as a potential bug high High priority proposal Proposal for a new functionality in Ocelot
Projects
None yet
4 participants