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

Testing webapi with openId #16385

Closed
hyzx86 opened this issue Jun 28, 2024 · 1 comment
Closed

Testing webapi with openId #16385

hyzx86 opened this issue Jun 28, 2024 · 1 comment

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Jun 28, 2024

I found that the authorisation used in our unit test was simulated, causing it to run differently than it would in a real environment

var permissions = (_permissionsContext.AuthorizedPermissions ?? []).ToList();
if (!_permissionsContext.UsePermissionsContext)
{
context.Succeed(requirement);
}
else if (permissions.Contains(requirement.Permission))
{
context.Succeed(requirement);
}
else
{
var grantingNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
GetGrantingNamesInternal(requirement.Permission, grantingNames);
// SiteOwner permission grants them all
grantingNames.Add(StandardPermissions.SiteOwner.Name);
if (permissions.Any(p => grantingNames.Contains(p.Name)))
{
context.Succeed(requirement);
}
else
{
context.Fail();
}
}
return Task.CompletedTask;

It is recommended to use OpenId requests to simulate requests in unit tests

We can use password streams to simulate different permission levels by creating users with different permissions
I'm validating this idea based on version 1.8.

@hyzx86 hyzx86 changed the title Use openId instead AuthenticationContext Testing webapi with openId Jun 28, 2024
@hyzx86
Copy link
Contributor Author

hyzx86 commented Jun 28, 2024

It doesn't look like there's much in the way of unit testing for OC that needs to be tested this way at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant