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

Begin porting OpenIddictServerBuilderTests from 2.x. #970

Merged

Conversation

Darthruneis
Copy link
Contributor

  • Some tests would not work without the changes to how the Options were retrieved.
  • The skipped tests are those that are currently failing on all frameworks.
    Will be continuing to try to fix those.
  • The commented out tests have compiler errors.
    Will need to go through and see which, if any, are still valid.

Related Work Items: #894

Posting this in a somewhat WIP state in case @kevinchalet has any feedback on the changes so far, and also to see what happens with the CI builds.

- Some tests would not work without the changes to how the Options were retrieved.
- The skipped tests are those that are currently failing on all frameworks.
Will be continuing to try to fix those.
- The commented out tests have compiler errors.
Will need to go through and see which, if any, are still valid.

Related Work Items: openiddict#894
Copy link
Member

@kevinchalet kevinchalet left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! I added a couple of notes that should help you with dependencies.

@kevinchalet kevinchalet changed the title Begin porting OpenIdDictServerBuilderTests from 2.x. Begin porting OpenIddictServerBuilderTests from 2.x. Jun 9, 2020
@Darthruneis
Copy link
Contributor Author

@kevinchalet One of the tests I was having trouble with were the certificate ones. What is the process used for generating the certificates used in the test projects? Is it just a self-signed cert created locally?

Reviewing your other comments now.

@kevinchalet
Copy link
Member

@kevinchalet One of the tests I was having trouble with were the certificate ones. What is the process used for generating the certificates used in the test projects? Is it just a self-signed cert created locally?

The certificates stored as embedded resources, they are indeed self-signed certificates.

Assuming you're referring to the 2 skipped tests - that use certificate generation - I suspect that's because the SUPPORTS_CERTIFICATE_GENERATION compilation constant is not set. You'll need to set if for all TFMs except net461 (e.g https://github.com/openiddict/openiddict-core/blob/dev/src/OpenIddict.Server/OpenIddict.Server.csproj#L33).

@Darthruneis
Copy link
Contributor Author

Yeah, I've got that line in there, but currently I don't have a certificate in the project. I was initially thinking I'd need to generate a new one, but I guess it should also be possible to just go back and get the one that was previously in the test project back in 2.x. That might be easier/less prone to new issues popping up in the test.

Remaining commented out tests are for methods that do not compile as the test is currently written.
Need to investigate whether these were truly removed or if maybe the namespace the extensions
come from are just not imported yet.
Copy link
Member

@kevinchalet kevinchalet left a comment

Choose a reason for hiding this comment

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

It looks excellent, thanks a lot!

Do you need help with the remaining tests?


private class CustomContext : BaseContext
{
/// <summary>
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the XML comments, they are not very useful in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resharper generated those when I used its 'generate missing members' functionality. I can remove them if you like, but it didn't take any time to add them either :).

// Arrange
var services = CreateServices();
var builder = CreateBuilder(services);
Action<OpenIddictServerHandlerDescriptor.Builder<CustomContext>> configuration = null;
Copy link
Member

Choose a reason for hiding this comment

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

To simply things, feel free to remove that and do builder.AddEventHandler<CustomContext>(configuration: null) like in the other tests.

Copy link
Contributor Author

@Darthruneis Darthruneis Jun 15, 2020

Choose a reason for hiding this comment

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

I used the variable so that I could use nameof(configuration) in the assertion, rather than hardcoding the string value for the assert. I avoid hardcoding strings when possible - do you think there's a negative to using nameof in this way in the context of a unit test?

Copy link
Member

@kevinchalet kevinchalet Jun 15, 2020

Choose a reason for hiding this comment

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

It's certainly not a bad practice, it's just that I haven't used this approach anywhere else, so it's a bit inconsistent. But I'm fine keeping it this way if you like it.

@Darthruneis
Copy link
Contributor Author

Do you need help with the remaining tests?

I think I've got most of the coverage of the ServerBuilder class now. Anything related to the certificates or encryption may need to be built out a bit more. I've shied away those due to a lack of experience working with certs/encryption.

Regarding the other classes which are referenced in #894 , I intend to start on those next. Do you have any preference between:

  • A different PR for each of the class that is being tested, or
  • a single PR (this one) to encompass all of 894?

@kevinchalet
Copy link
Member

FYI, the fact you're using action delegate variables results in VS adding many "info" messages suggesting replacing them by local functions:

image

This is not blocking for this PR, but to reduce the noise in VS, you'll want probably want to avoid the intermediate variable and do Assert.Throws<ArgumentNullException>(() => builder.AddEncryptionKey(key)).

I think I've got most of the coverage of the ServerBuilder class now. Anything related to the certificates or encryption may need to be built out a bit more. I've shied away those due to a lack of experience working with certs/encryption.

Great. I'll take a look once this PR is merged.

Regarding the other classes which are referenced in #894 , I intend to start on those next. Do you have any preference between.

No preference. Feel free to opt for the one who better suits your flow. If you opt for the second option, please let me know and I'll merge this PR today.

Thanks!

@Darthruneis
Copy link
Contributor Author

Updated to clean up those info messages. I've had info messages turned off in VS for ages so I had no idea it was polluting those up so much.

As for the PR, I prefer to merge it in then. Easier to make a new branch then and work on the next set of tests that need ported, and it allows the tests to be in place as the safety net they hopefully will act as.

@kevinchalet kevinchalet merged commit f9d9762 into openiddict:dev Jun 19, 2020
@kevinchalet
Copy link
Member

PR merged, thanks a lot for your contribution! 👏

@kevinchalet kevinchalet self-assigned this Jun 19, 2020
@kevinchalet kevinchalet added this to the 3.0.0-beta2 milestone Jun 19, 2020
@Darthruneis Darthruneis deleted the 894-PortOpenIddictServerBuilderTests branch August 2, 2020 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants