Skip to content

Commit

Permalink
Moved bitbucket username out as a secret since it has to match the pa…
Browse files Browse the repository at this point in the history
…ssword for that user
  • Loading branch information
ToreMerkely committed Oct 21, 2024
1 parent 6bc0d29 commit 2748da9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 52 deletions.
6 changes: 3 additions & 3 deletions cmd/kosli/assertPRBitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ func (suite *AssertPRBitbucketCommandTestSuite) TestAssertPRBitbucketCmd() {
tests := []cmdTestCase{
{
name: "assert Bitbucket PR evidence passes when commit has a PR in bitbucket",
cmd: `assert pullrequest bitbucket --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test
cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test
--commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
golden: "found [1] pull request(s) in Bitbucket for commit: fd54040fc90e7e83f7b152619bfa18917b72c34f\n",
},
{
wantError: true,
name: "assert Bitbucket PR evidence fails when commit has no PRs in bitbucket",
cmd: `assert pullrequest bitbucket --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test
cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test
--commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments,
golden: "Error: assert failed: found no pull request(s) in Bitbucket for commit: 3dce097040987c4693d2e4be817474d9d0063c93\n",
},
{
wantError: true,
name: "assert Bitbucket PR evidence fails when commit does not exist",
cmd: `assert pullrequest bitbucket --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test
cmd: `assert pullrequest bitbucket --bitbucket-workspace kosli-dev --repository cli-test
--commit 19aab7f063147614451c88969602a10afba123ab` + suite.defaultKosliArguments,
golden: "Error: map[error:map[message:Resource not found] type:error]\n",
},
Expand Down
16 changes: 8 additions & 8 deletions cmd/kosli/attestPRBitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (suite *AttestBitbucketPRCommandTestSuite) TestAttestBitbucketPRCmd() {
wantError: true,
name: "fails when missing a required flags",
cmd: fmt.Sprintf("attest pullrequest bitbucket foo -t file %s", suite.defaultKosliArguments),
golden: "Error: required flag(s) \"bitbucket-username\", \"bitbucket-workspace\", \"name\", \"repository\" not set\n",
golden: "Error: required flag(s) \"bitbucket-workspace\", \"name\", \"repository\" not set\n",
},
{
wantError: true,
Expand All @@ -80,43 +80,43 @@ func (suite *AttestBitbucketPRCommandTestSuite) TestAttestBitbucketPRCmd() {
wantError: true,
name: "attesting against an artifact that does not exist fails",
cmd: fmt.Sprintf(`attest pullrequest bitbucket --fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint 1234e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 does not exist in trail \"test-123\" of flow \"attest-bitbucket-pr\" belonging to organization \"docs-cmd-test-user\"\n",
},
{
name: "can attest bitbucket pr against an artifact using artifact name and --artifact-type",
cmd: fmt.Sprintf(`attest pullrequest bitbucket testdata/file1 --artifact-type file --name foo
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n",
},
{
name: "can attest bitbucket pr against an artifact using artifact name and --artifact-type when --name does not exist in the trail template",
cmd: fmt.Sprintf(`attest pullrequest bitbucket testdata/file1 --artifact-type file --name bar
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'bar' is reported to trail: test-123\n",
},
{
name: "can attest bitbucket pr against an artifact using --fingerprint",
cmd: fmt.Sprintf(`attest pullrequest bitbucket --fingerprint 7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9 --name foo
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n",
},
{
name: "can attest bitbucket pr against a trail",
cmd: fmt.Sprintf(`attest pullrequest bitbucket --name bar
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'bar' is reported to trail: test-123\n",
},
{
name: "can attest bitbucket pr against a trail when name is not found in the trail template",
cmd: fmt.Sprintf(`attest pullrequest bitbucket --name additional
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'additional' is reported to trail: test-123\n",
},
{
name: "can attest bitbucket pr against an artifact it is created using dot syntax in --name",
cmd: fmt.Sprintf(`attest pullrequest bitbucket --name cli.foo
--bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
--bitbucket-workspace kosli-dev --repository cli-test %s`, suite.defaultKosliArguments),
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request attestation 'foo' is reported to trail: test-123\n",
},
}
Expand Down
33 changes: 13 additions & 20 deletions cmd/kosli/reportEvidenceArtifactPRBitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,101 +39,94 @@ func (suite *ArtifactEvidencePRBitbucketCommandTestSuite) TestArtifactEvidencePR
{
name: "report Bitbucket PR evidence works with new flags (fingerprint, name ...)",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --org is missing",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f --api-token foo --host bar`,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f --api-token foo --host bar`,
goldenRegex: "Error: --org is not set\n" +
"Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --name is missing",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: required flag\\(s\\) \"name\" not set\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --bitbucket-username is missing",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: required flag\\(s\\) \"bitbucket-username\" not set\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --repository is missing",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: required flag\\(s\\) \"repository\" not set\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --commit is missing",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test` + suite.defaultKosliArguments,
goldenRegex: "Error: required flag\\(s\\) \"commit\" not set\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when neither --fingerprint nor --artifact-type are set",
cmd: `report evidence artifact pullrequest bitbucket artifactNameArg --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: either --artifact-type or --fingerprint must be specified\n" +
"Usage: kosli report evidence artifact pullrequest bitbucket \\[IMAGE-NAME | FILE-PATH | DIR-PATH\\] \\[flags\\]\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when commit does not exist",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 73d7fee2f31ade8e1a9c456c324255212c3123ab` + suite.defaultKosliArguments,
goldenRegex: "Error: map\\[error:map\\[message:Resource not found\\] type:error\\]\n",
},
{
name: "report Bitbucket PR evidence works when --assert is used and commit has a PR",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--assert
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --assert is used and commit has no PRs",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--assert
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments,
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\nError: assert failed: no pull request found for the given commit: .*\n",
},
{
name: "report Bitbucket PR evidence does not fail when commit has no PRs",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit 3dce097040987c4693d2e4be817474d9d0063c93` + suite.defaultKosliArguments,
goldenRegex: "found 0 pull request\\(s\\) for commit: .*\nbitbucket pull request evidence is reported to artifact: .*\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when the artifact does not exist in the server",
cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type file --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "found 1 pull request\\(s\\) for commit: .*\nError: Artifact with fingerprint '7509e5bda0c762d2bac7f90d758b5b2263fa01ccbc542ab5e3df163be08e6ca9' does not exist in flow 'bitbucket-pr' belonging to organization 'docs-cmd-test-user'. \n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --artifact-type is unsupported",
cmd: `report evidence artifact pullrequest bitbucket testdata/file1 --artifact-type unsupported --name bb-pr --flow ` + suite.flowName + `
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: unsupported is not a supported artifact type\n",
},
{
wantError: true,
name: "report Bitbucket PR evidence fails when --user-data is not found",
cmd: `report evidence artifact pullrequest bitbucket --fingerprint ` + suite.artifactFingerprint + ` --name bb-pr --flow ` + suite.flowName + `
--user-data non-existing.json
--build-url http://www.example.com --bitbucket-username tore1 --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
--build-url http://www.example.com --bitbucket-workspace kosli-dev --repository cli-test --commit fd54040fc90e7e83f7b152619bfa18917b72c34f` + suite.defaultKosliArguments,
goldenRegex: "Error: open non-existing.json: no such file or directory\n",
},
}
Expand Down
Loading

0 comments on commit 2748da9

Please sign in to comment.