-
Notifications
You must be signed in to change notification settings - Fork 124
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
Tag oidc unit tests #2706
Tag oidc unit tests #2706
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamouamani What do you think? Do tests that leverage a DataObject
in conjunction with another module always constitute as an integration test? https://github.com/cyberark/conjur/pull/2706/files#diff-cf99fb4eccb8c5d8aaeb05adb7d5063d743d31d8bd623cc38f878b318620bd60R41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamouamani Here's another example of a test that uses a mock and a data object. Should it be considered a unit test or an integration test? https://github.com/cyberark/conjur/pull/2706/files#diff-ecc086dac9693ffbe9eba71f440388e8e466250eae64880dadaef7f13f37ddf1R110
8bd5d9b
to
f607512
Compare
Hi @jvanderhoof and @adamouamani, Currently, we have questions on the following tests (currently tagged with
|
Here's another one @jvanderhoof and @adamouamani,
|
And another, @jvanderhoof, @adamouamani
|
@codihuston - you have highlighted a lot of great cases that we can review with @jvanderhoof and document and create a pattern we can apply for other tests! |
@codihuston, (cc. @adamouamani), my personal opinion is that the first two examples:
are both appropriate unit tests because they take advantage of dependency injection as alternative to excessive mocking. The We don't need to mock the data object, because it's essentially a mock already (but it's the real object). For this reason, I'd consider the first two examples appropriate to call unit tests on. |
@codihuston, (cc. @adamouamani). I do want to state that mocking must be understood as a code smell, albeit one which is necessary in any software which takes in external data (essentially all of them). Mocking is highly problematic as it requires two definitions of a single interface: one for the class being mocked, the second, the mock of the class. Mocks are necessary when we deal with outside data (loading from database, API requests, user input, etc.). Dependency inject simplifies the process of mocking (which is why we push this pattern), but any mocking is a poor substitute for the actual dependent object. |
@codihuston, (cc. @adamouamani), I'd also classify the third item (spec/app/domain/authentication/authn-oidc/pkce_support_feature/client_spec.rb) as being appropriate as a unit test give the same argument as above. I do think it's very important to understand the risk in the mocked OIDC client in this test. We're using VCR to mock the OIDC client wrapped in this class. The danger in our mock is that if the upstream OIDC API changes, our tests will continue to pass. This is why it's important to have a few E2E tests over all this. Unit tests can only identify that when given a particular set of pre-defined inputs, the method returns an expected output. |
@codihuston, @adamouamani, I really should have started with the fact that I really like this approach! It's simple, natively part of RSpec, and gives more context to a particular test. Well done!!!! |
@codihuston @jvanderhoof This is a fantastic start! I'll update the confluence page with approach, feedback from Jason and examples to help people determine test type when evaluating additional modules in the future. https://ca-il-confluence.il.cyber-ark.com/display/rndp/Test+Level+Review+Patterns |
f607512
to
2326937
Compare
@adamouamani Awesome! We've only come out of this effort with identifying unit tests--should we consider merging this PR as is, or should we shelf it for the time being until we tag and review some true integration tests? If so, let me know and I'll mark this ready for review / undraft it. Note: no changes have been added in the pipeline to leverage this tag (I believe we weren't planning on doing this anytime soon). |
@codihuston I would merge this and finish any remaining updates to docs on confluence if anything that I missed. We can then create a follow-up story to continue this effort for another section/module with more integration tests examples |
2326937
to
5db1fbd
Compare
Hey @jvanderhoof , this PR contains a commit that adds tests that were being ignored by rspec due to some files not following the It looks like one of the oidc pkce strategy tests were failing when expecting a specific error code to be thrown, but it turns out a different error code was being thrown instead. I updated the test to account for that, but can you confirm that this is the intended behavior please? Thanks!
|
Good catch. I just found and fixed this issue here: #2713. |
You can display the tagged the tests with the following command(s). Drop the `--dry-run` to actually run the tests: ```bash rspec -f d --color --dry-run --tag @type:unit ```
5db1fbd
to
f621ed6
Compare
Code Climate has analyzed commit f621ed6 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 90.0% (-1.5% change). View more on Code Climate. |
Thanks Jason! I dropped those commits from this PR--it only contains the labeling effort then. Appreciate it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @codihuston
To run the tests, start conjur dev environment:
cd git/conjur/dev ./start
Exec into the conjur container and run the tests:
Desired Outcome
First round of unittags to rspec tests for oidc pkce and v2.
See the above commands for visualizing which tests have been tagged.
Implemented Changes
Describe how the desired outcome above has been achieved with this PR. In
particular, consider:
What's changed? Why were these changes made?
_rspec.rb
vs_spec.rb
How should the reviewer approach this PR, especially if manual tests are required?
Are there relevant screenshots you can add to the PR description?
Connected Issue/Story
CyberArk internal issue ID: [CNJR-178]
Definition of Done
At least 1 todo must be completed in the sections below for the PR to be
merged.
Changelog
CHANGELOG update
Test coverage
changes, or
Documentation
README
s) were updated in this PRBehavior
Security