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

fix: dont emit empty strings when reading role #66

Merged
merged 4 commits into from
Apr 18, 2023

Conversation

TJM
Copy link
Contributor

@TJM TJM commented Apr 18, 2023

Now when the role is read, it looks like:

$ vault read artifactory/roles/test
Key            Value
---            -----
default_ttl    2h
max_ttl        3h
role           test
scope          applied-permissions/groups:readers

@TJM TJM requested a review from alexhung as a code owner April 18, 2023 03:08
alexhung
alexhung previously approved these changes Apr 18, 2023
Copy link
Member

@alexhung alexhung left a comment

Choose a reason for hiding this comment

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

:shipit:

Out of interest, have you tried running acceptance tests using make acceptance? Want to know if it works for others outside JFrog dev team.

@@ -283,7 +298,7 @@ make artifactory

```sh
export VAULT_ADDR=http://localhost:8200
export VAULT_token=root
export VAULT_TOKEN=root
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

@alexhung alexhung requested a review from shrajfr12 April 18, 2023 16:10
@TJM
Copy link
Contributor Author

TJM commented Apr 18, 2023

:shipit:

Out of interest, have you tried running acceptance tests using make acceptance? Want to know if it works for others outside JFrog dev team.

I just tried it, and it didn't go well.. I had "make start" in one window, "make artifactory" and "make setup" were done, but "make acceptance" failed a lot :)

[tmcneely@local artifactory-secrets-plugin]$ make acceptance
export VAULT_ACC=true && \
		go test -run TestAcceptance -cover -coverprofile=coverage.txt -v -p 1 -timeout 5m ./...
Logging in to Artifactory (http://localhost:8082) as admin ...
Generating artifactory admin access token.
=== RUN   TestAcceptanceBackend_PathRotate
2023-04-18T11:06:27.005-0600 [WARN]  error making system version request: response=<nil> err="parse "": empty url"
    test_utils.go:44: parse "": empty url
--- FAIL: TestAcceptanceBackend_PathRotate (0.00s)
=== RUN   TestAcceptanceBackend_PathConfig
=== RUN   TestAcceptanceBackend_PathConfig/update
    test_utils.go:91:
        	Error Trace:	test_utils.go:91
        	Error:      	Expected nil, but got: &logical.Response{Secret:<nil>, Auth:<nil>, Data:map[string]interface {}{"error":"access_token is required"}, Redirect:"", Warnings:[]string(nil), WrapInfo:(*wrapping.ResponseWrapInfo)(nil), Headers:map[string][]string(nil)}
        	Test:       	TestAcceptanceBackend_PathConfig/update
=== RUN   TestAcceptanceBackend_PathConfig/read
    test_utils.go:103:
        	Error Trace:	test_utils.go:103
        	Error:      	Should NOT be empty, but was <nil>
        	Test:       	TestAcceptanceBackend_PathConfig/read
=== RUN   TestAcceptanceBackend_PathConfig/delete
--- FAIL: TestAcceptanceBackend_PathConfig (0.00s)
    --- FAIL: TestAcceptanceBackend_PathConfig/update (0.00s)
    --- FAIL: TestAcceptanceBackend_PathConfig/read (0.00s)
    --- PASS: TestAcceptanceBackend_PathConfig/delete (0.00s)
=== RUN   TestAcceptanceBackend_PathRole
=== RUN   TestAcceptanceBackend_PathRole/configure_backend
    test_utils.go:91:
        	Error Trace:	test_utils.go:91
        	Error:      	Expected nil, but got: &logical.Response{Secret:<nil>, Auth:<nil>, Data:map[string]interface {}{"error":"access_token is required"}, Redirect:"", Warnings:[]string(nil), WrapInfo:(*wrapping.ResponseWrapInfo)(nil), Headers:map[string][]string(nil)}
        	Test:       	TestAcceptanceBackend_PathRole/configure_backend
=== RUN   TestAcceptanceBackend_PathRole/create
    test_utils.go:202:
        	Error Trace:	test_utils.go:202
        	Error:      	Expected nil, but got: &logical.Response{Secret:<nil>, Auth:<nil>, Data:map[string]interface {}{"error":"backend not configured"}, Redirect:"", Warnings:[]string{"Endpoint replaced the value of these parameters with the values captured from the endpoint's path: [role]"}, WrapInfo:(*wrapping.ResponseWrapInfo)(nil), Headers:map[string][]string(nil)}
        	Test:       	TestAcceptanceBackend_PathRole/create
=== RUN   TestAcceptanceBackend_PathRole/read
    test_utils.go:212:
        	Error Trace:	test_utils.go:212
        	Error:      	Expected value not to be nil.
        	Test:       	TestAcceptanceBackend_PathRole/read
--- FAIL: TestAcceptanceBackend_PathRole (0.00s)
    --- FAIL: TestAcceptanceBackend_PathRole/configure_backend (0.00s)
    --- FAIL: TestAcceptanceBackend_PathRole/create (0.00s)
    --- FAIL: TestAcceptanceBackend_PathRole/read (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x1641e51]

goroutine 26 [running]:
testing.tRunner.func1.2({0x16e2b60, 0x1d06900})
	/Users/tmcneely/.asdf/installs/golang/1.20.3/go/src/testing/testing.go:1526 +0x24e
testing.tRunner.func1()
	/Users/tmcneely/.asdf/installs/golang/1.20.3/go/src/testing/testing.go:1529 +0x39f
panic({0x16e2b60, 0x1d06900})
	/Users/tmcneely/.asdf/installs/golang/1.20.3/go/src/runtime/panic.go:884 +0x213
github.com/jfrog/artifactory-secrets-plugin.(*accTestEnv).ReadPathRole(0xc0002a6d20, 0x10cdc17?)
	/Users/tmcneely/Projects/Artifactory/artifactory-secrets-plugin/test_utils.go:215 +0x131
testing.tRunner(0xc00026fd40, 0xc000297170)
	/Users/tmcneely/.asdf/installs/golang/1.20.3/go/src/testing/testing.go:1576 +0x10b
created by testing.(*T).Run
	/Users/tmcneely/.asdf/installs/golang/1.20.3/go/src/testing/testing.go:1629 +0x3ea
FAIL	github.com/jfrog/artifactory-secrets-plugin	0.486s
?   	github.com/jfrog/artifactory-secrets-plugin/cmd/artifactory	[no test files]
FAIL
make: *** [acceptance] Error 1

NOTE: Vault and Artifactory are still running, it was the test that segfaulted.
(second paste, I added the exports for ARTIFACTORY_URL and JFROG_ACCESS_TOKEN

EDIT: This has been fixed, see below. The variables are actually JFROG_URL and ARTIFACTORY_ACCESS_TOKEN (we will change that in a future MR)

ARTIFACTORY_URL ?= http://localhost:8082
JFROG_ACCESS_TOKEN ?= $(shell TOKEN_USERNAME=$(TOKEN_USERNAME) ARTIFACTORY_URL=$(ARTIFACTORY_URL) ./scripts/getArtifactoryAdminToken.sh)
export ARTIFACTORY_URL ?= http://localhost:8082
export JFROG_ACCESS_TOKEN ?= $(shell TOKEN_USERNAME=$(TOKEN_USERNAME) ARTIFACTORY_URL=$(ARTIFACTORY_URL) ./scripts/getArtifactoryAdminToken.sh)
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼 I export them in my shell manually. Hence I didn't run into this problem until it's being run in clean env.

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 even tried with them manually exported and got very similar output

Copy link
Member

Choose a reason for hiding this comment

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

The tests actually are using JFROG_URL and ARTIFACTORY_ACCESS_TOKEN. I guess we should update them to use the same...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, the readme says ARTIFACTORY_URL and JFROG_ACCESS_TOKEN :) .. yes, do you want me to add that to this PR or is it already bloated enough? :)

Copy link
Member

Choose a reason for hiding this comment

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

Let's have separate PR 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

[tmcneely@local artifactory-secrets-plugin]$ make acceptance
export VAULT_ACC=true && \
		go test -run TestAcceptance -cover -coverprofile=coverage.txt -v -p 1 -timeout 5m ./...
Logging in to Artifactory (http://localhost:8082) as admin ...
Generating artifactory admin access token.
=== RUN   TestAcceptanceBackend_PathRotate
2023-04-18T12:26:49.916-0600 [DEBUG] oldToken ID: ddc8d463-0fd1-42d0-b2fe-6a25b514566e
2023-04-18T12:26:49.924-0600 [DEBUG] newTokenID: 2e576145-e34e-41a7-aa48-5d812bfcd28f
--- PASS: TestAcceptanceBackend_PathRotate (2.14s)
=== RUN   TestAcceptanceBackend_PathConfig
=== RUN   TestAcceptanceBackend_PathConfig/update
=== RUN   TestAcceptanceBackend_PathConfig/read
=== RUN   TestAcceptanceBackend_PathConfig/delete
--- PASS: TestAcceptanceBackend_PathConfig (0.01s)
    --- PASS: TestAcceptanceBackend_PathConfig/update (0.00s)
    --- PASS: TestAcceptanceBackend_PathConfig/read (0.01s)
    --- PASS: TestAcceptanceBackend_PathConfig/delete (0.00s)
=== RUN   TestAcceptanceBackend_PathRole
=== RUN   TestAcceptanceBackend_PathRole/configure_backend
=== RUN   TestAcceptanceBackend_PathRole/create
=== RUN   TestAcceptanceBackend_PathRole/read
=== RUN   TestAcceptanceBackend_PathRole/delete
=== RUN   TestAcceptanceBackend_PathRole/cleanup_backend
--- PASS: TestAcceptanceBackend_PathRole (0.00s)
    --- PASS: TestAcceptanceBackend_PathRole/configure_backend (0.00s)
    --- PASS: TestAcceptanceBackend_PathRole/create (0.00s)
    --- PASS: TestAcceptanceBackend_PathRole/read (0.00s)
    --- PASS: TestAcceptanceBackend_PathRole/delete (0.00s)
    --- PASS: TestAcceptanceBackend_PathRole/cleanup_backend (0.00s)
=== RUN   TestAcceptanceBackend_PathTokenCreate
=== RUN   TestAcceptanceBackend_PathTokenCreate/configure_backend
=== RUN   TestAcceptanceBackend_PathTokenCreate/create_role
=== RUN   TestAcceptanceBackend_PathTokenCreate/create_token_for_role
=== RUN   TestAcceptanceBackend_PathTokenCreate/delete_role
=== RUN   TestAcceptanceBackend_PathTokenCreate/cleanup_backend
--- PASS: TestAcceptanceBackend_PathTokenCreate (0.02s)
    --- PASS: TestAcceptanceBackend_PathTokenCreate/configure_backend (0.01s)
    --- PASS: TestAcceptanceBackend_PathTokenCreate/create_role (0.00s)
    --- PASS: TestAcceptanceBackend_PathTokenCreate/create_token_for_role (0.01s)
    --- PASS: TestAcceptanceBackend_PathTokenCreate/delete_role (0.00s)
    --- PASS: TestAcceptanceBackend_PathTokenCreate/cleanup_backend (0.00s)
PASS
	github.com/jfrog/artifactory-secrets-plugin	coverage: 62.7% of statements
ok  	github.com/jfrog/artifactory-secrets-plugin	2.648s	coverage: 62.7% of statements
?   	github.com/jfrog/artifactory-secrets-plugin/cmd/artifactory	[no test files]

@alexhung alexhung mentioned this pull request Apr 18, 2023
@alexhung alexhung merged commit d8a29c0 into jfrog:master Apr 18, 2023
2 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.

None yet

2 participants