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

Dedupe $ProductNames #782

Merged
merged 6 commits into from
May 31, 2024
Merged

Dedupe $ProductNames #782

merged 6 commits into from
May 31, 2024

Conversation

twneale
Copy link
Collaborator

@twneale twneale commented Jan 9, 2024

πŸ—£ Description

Remove duplicate items from the $ProductNames list to avoid running checks repeatedly.

Environment: Powershell 7 on Ubuntu 22.04.3 LTS

πŸ’­ Motivation and context

Resolves #171

Including the same product twice in $ProductNames runs the checks multiple times unecessarily.

πŸ§ͺ Testing

I ran Invoke-SCuBA -ProductNames aad,aad,aad,aad,aad,aad ... before and after the change to observe whether it authenticated multiple times.

βœ… Pre-approval checklist

  • This PR has an informative and human-readable title.
  • Changes are limited to a single goal - eschew scope creep!
  • All future TODOs are captured in issues, which are referenced
    in code comments.
  • All relevant type-of-change labels have been added.
  • I have read the CONTRIBUTING document.
  • These code changes follow cisagov code standards.
  • All relevant repo and/or project documentation has been updated
    to reflect the changes in this PR.
  • Tests have been added and/or modified to cover the changes in this PR.
  • All new and existing tests pass.

βœ… Pre-merge checklist

  • Revert dependencies to default branches.
  • Finalize version.

βœ… Post-merge checklist

  • Create a release.

@twneale twneale changed the title 171 dedupe productnames fix Dedupe $ProductNames Jan 9, 2024
@schrolla schrolla added the bug This issue or pull request addresses broken functionality label Jan 18, 2024
@schrolla schrolla added this to the Flipper milestone Jan 18, 2024
@schrolla schrolla changed the base branch from flipper to main January 19, 2024 15:27
@schrolla
Copy link
Collaborator

@twneale Successfully migrated from flipper to main branch with rebase. If you have a local checkout be sure to do a git pull --rebase to get the latest version in your local repo.

@twneale
Copy link
Collaborator Author

twneale commented Jan 22, 2024

@schrolla I'm trying to figure out "Tests have been added and/or modified to cover the changes in this PR." Since I didn't add any new lines of code, there's no need for additional code coverage, but I could modify a file like ./Testing/Functional/Auto/MinimumTest.txt to add a duplicate entry to one of the command lists. But I don't think there is an economical way to actually check whether the orchestrator repeats the provider export multiple times, at least not without adding a lot of additional code to keep track of that info. I ran it locally and confirmed it works as expected, just not sure how to proceed with this particular checkbox.

@schrolla
Copy link
Collaborator

@schrolla I'm trying to figure out "Tests have been added and/or modified to cover the changes in this PR." Since I didn't add any new lines of code, there's no need for additional code coverage, but I could modify a file like ./Testing/Functional/Auto/MinimumTest.txt to add a duplicate entry to one of the command lists. But I don't think there is an economical way to actually check whether the orchestrator repeats the provider export multiple times, at least not without adding a lot of additional code to keep track of that info. I ran it locally and confirmed it works as expected, just not sure how to proceed with this particular checkbox.

How about a unit test that tries to run with duplicate products specified with an expectation that it will fail? Could be done with a new PS unit pester test. That way, the new test validates the result of the code change works as intended and we have code coverage for the change to prevent a regression.

@crutchfield
Copy link
Contributor

@schrolla I'm trying to figure out "Tests have been added and/or modified to cover the changes in this PR." Since I didn't add any new lines of code, there's no need for additional code coverage, but I could modify a file like ./Testing/Functional/Auto/MinimumTest.txt to add a duplicate entry to one of the command lists. But I don't think there is an economical way to actually check whether the orchestrator repeats the provider export multiple times, at least not without adding a lot of additional code to keep track of that info. I ran it locally and confirmed it works as expected, just not sure how to proceed with this particular checkbox.

How about a unit test that tries to run with duplicate products specified with an expectation that it will fail? Could be done with a new PS unit pester test. That way, the new test validates the result of the code change works as intended and we have code coverage for the change to prevent a regression.

I'd suggest adding to Invoke-Scuba.Tests.ps1. Mock out Invoke-ReportCreation and see that a unique list is passed even if dupes are originally passed into InvokeScuba.

@twneale twneale requested review from crutchfield and Dylan-MITRE and removed request for Dylan-MITRE and tkol2022 January 23, 2024 19:28
@twneale
Copy link
Collaborator Author

twneale commented Jan 24, 2024

I added some tests to verify that it works. I tried the approach @crutchfield suggested and added once for the case of ScubaConfig as well.

Copy link
Contributor

@Dylan-MITRE Dylan-MITRE left a comment

Choose a reason for hiding this comment

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

Ran Invoke-SCuBA -ProductNames in different variation and order, such as:

  • aad, aad
  • aad, aad, teams
  • aad, aad, teams, teams
  • teams, exo, defender, aad, sharepoint, teams
    all works as expected.

Invoke-Scuba.Tests.ps1 works as well

ScubaConfigJsonDuplicateProviderTests.ps1 however give me an error when i run it
Screenshot 2024-01-24 at 1 23 31β€―PM

@twneale
Copy link
Collaborator Author

twneale commented Jan 24, 2024

Thank you for running it @Dylan-MITRE. My test is messed up. I will take another swing at it.

Copy link
Contributor

@crutchfield crutchfield left a comment

Choose a reason for hiding this comment

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

Maybe we should fix at least ResetInstance/ClearConfiguration as part of this PR. Otherwise I believe testing is more difficult.

@twneale
Copy link
Collaborator Author

twneale commented Jan 25, 2024

This shouldn't be merged yet. I discovered the in powershell, sort-object -unique returns an array only if the sorted result contains more than two elements. If it only contains one element, it returns a string πŸ€¦β€β™‚οΈ. So despite passing tests, my changes actually return ProductNames as a string which I'm not sure is correct. I should probably confirm with @crutchfield whether this is what's expected when there's only one product name.

@twneale twneale added the blocked This issue or pull request is awaiting the outcome of another issue or pull request label Jan 31, 2024
@twneale twneale modified the milestones: Flipper, Glacier Jan 31, 2024
@schrolla
Copy link
Collaborator

schrolla commented Feb 5, 2024

@twneale Is this actually blocked, or did you add blocked to prevent merge? If the latter, recommend setting the PR to draft state until updates can be made and removing the blocked label instead. Draft PRs can't be merged, blocked ones, technically speaking, can.

@twneale twneale removed the blocked This issue or pull request is awaiting the outcome of another issue or pull request label Feb 5, 2024
@twneale twneale marked this pull request as draft February 5, 2024 17:41
@schrolla schrolla modified the milestones: Glacier, Halibut Mar 21, 2024
@twneale
Copy link
Collaborator Author

twneale commented May 16, 2024

@schrolla I think this is ready for review. Overall, I don't think the actual code changes truly justify the volume of tests and general controversy this PR created, so I am equally fine just closing it without merging.

@twneale twneale marked this pull request as ready for review May 16, 2024 14:52
Copy link
Collaborator

@nanda-katikaneni nanda-katikaneni left a comment

Choose a reason for hiding this comment

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

Tested with duplicate product names - ScubaGear now runs for each product once even if its duplicated in the productname parameter. Looks good to me.

Copy link
Collaborator

@ahuynhMITRE ahuynhMITRE left a comment

Choose a reason for hiding this comment

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

tested with a couple iterations of duplicate products with no issues. Nothing further from me.

@nanda-katikaneni
Copy link
Collaborator

@twneale can you please rebase the branch and also resolve some of earlier comments (not sure if they are addressed), thanks.

@twneale twneale force-pushed the 171-dedupe-productnames-fix branch from d1b4ddd to 997157b Compare May 31, 2024 16:24
@nanda-katikaneni nanda-katikaneni merged commit a4a156d into main May 31, 2024
14 checks passed
@nanda-katikaneni nanda-katikaneni deleted the 171-dedupe-productnames-fix branch May 31, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue or pull request addresses broken functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product names list not check for unique
6 participants