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

test(policychecks): Implement IamPolicyChecks unit tests #5570

Merged
merged 3 commits into from
Oct 2, 2024

Conversation

kevluu-aws
Copy link
Contributor

Problem

IamPolicyChecks currently has no unit tests. This makes the feature fragile to changes and at risk to breaking changes.

Solution

Implement unit tests for IamPolicyChecks feature.
Note: Functions that require execFileSync were skipped as it was not possible to stub the execution of the underlying CLI tools used.


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kevluu-aws kevluu-aws requested review from a team as code owners September 11, 2024 02:06
@kevluu-aws kevluu-aws changed the title test(PolicyChecks): Implement IamPolicyChecks unit tests test(policychecks): Implement IamPolicyChecks unit tests Sep 11, 2024
Comment on lines +515 to +516
executeCustomPolicyChecksCommandStub.calledOnceWith({
command: 'cfn-policy-validator',
Copy link
Contributor

Choose a reason for hiding this comment

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

can you download the actual tool in CI and actually invoke it, instead of stubbing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we want to call the actual tool as it makes calls to an actual AWS service and requires credentials. Do we have a set of credentials we use for testing AWS services here? If we do, I think we can do it; the test will depend on the availability of the service in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

currently our CI only has a Builder Id token, not IAM credentials

@justinmk3
Copy link
Contributor

Functions that require execFileSync were skipped as it was not possible to stub the execution of the underlying CLI tools used.

Why is execFileSync being used in the app code? Our ChildProcess module should be used instead:

} catch (err) {
logger.error(err as Error)
}
}

// Helper function to get document contents from a path
async function _readCustomChecksFile(input: string): Promise<string> {
export async function _readCustomChecksFile(input: string): Promise<string> {
if (fs.existsSync(input)) {
return fs.readFileSync(input).toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

please migrate the app code to use our fs.ts module, do not use nodefs directly

import * as iamPolicyChecks from '../../../awsService/accessanalyzer/vue/iamPolicyChecks'
import * as vscode from 'vscode'
import { IamPolicyChecksConstants } from '../../../awsService/accessanalyzer/vue/constants'
import { FileSystem } from '../../../shared/fs/fs'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { FileSystem } from '../../../shared/fs/fs'
import fs from '../../../shared/fs/fs'

@justinmk3 justinmk3 merged commit a4bc012 into aws:master Oct 2, 2024
20 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants