-
Notifications
You must be signed in to change notification settings - Fork 5
validate capi-auth-token on dqlite/remove #56
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
Merged
HomayoonAlimohammadi
merged 9 commits into
dqlite-remove-endpoint
from
KU-1719/validate-capi-auth-token-on-remove
Oct 11, 2024
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
55a739f
Validate capi-auth-token on dqlite/remove
HomayoonAlimohammadi d41addb
Fix lint
HomayoonAlimohammadi f5d5ad2
Address comments and issues
HomayoonAlimohammadi 22a3bb7
Address comments and issues
HomayoonAlimohammadi e711313
Fix test
HomayoonAlimohammadi 2bcaeca
Add middleware for capi auth token
HomayoonAlimohammadi 2496acf
Fix lint
HomayoonAlimohammadi 6e986af
Revert "Fix lint"
HomayoonAlimohammadi f4e5819
Revert "Add middleware for capi auth token"
HomayoonAlimohammadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package cmd | ||
|
|
||
| const ( | ||
| capiDefaultPath = "/capi" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package v2 | ||
|
|
||
| const ( | ||
| // CAPIAuthTokenHeader is the header used to pass the CAPI auth token. | ||
| CAPIAuthTokenHeader = "capi-auth-token" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package snap_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| "github.com/canonical/microk8s-cluster-agent/pkg/snap" | ||
| ) | ||
|
|
||
| func TestCAPIAuthToken(t *testing.T) { | ||
| capiTestPath := "./capi-test" | ||
| os.RemoveAll(capiTestPath) | ||
| s := snap.NewSnap("", "", "", capiTestPath) | ||
| token := "token123" | ||
|
|
||
| g := NewWithT(t) | ||
|
|
||
| isValid, err := s.IsCAPIAuthTokenValid(token) | ||
| g.Expect(err).To(MatchError(os.ErrNotExist)) | ||
| g.Expect(isValid).To(BeFalse()) | ||
|
|
||
| capiEtc := filepath.Join(capiTestPath, "etc") | ||
| defer os.RemoveAll(capiTestPath) | ||
| g.Expect(os.MkdirAll(capiEtc, 0755)).To(Succeed()) | ||
| g.Expect(os.WriteFile("./capi-test/etc/token", []byte(token), 0600)).To(Succeed()) | ||
|
|
||
| isValid, err = s.IsCAPIAuthTokenValid("random-token") | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(isValid).To(BeFalse()) | ||
|
|
||
| isValid, err = s.IsCAPIAuthTokenValid(token) | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(isValid).To(BeTrue()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.