-
Notifications
You must be signed in to change notification settings - Fork 512
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
command to purge all keys from all delegations below a starting point #855
Merged
+496
−96
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 |
---|---|---|
|
@@ -14,23 +14,36 @@ import ( | |
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var testTrustDir = "trust_dir" | ||
|
||
func setup() *delegationCommander { | ||
func setup(trustDir string) *delegationCommander { | ||
return &delegationCommander{ | ||
configGetter: func() (*viper.Viper, error) { | ||
mainViper := viper.New() | ||
mainViper.Set("trust_dir", testTrustDir) | ||
mainViper.Set("trust_dir", trustDir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. \o/ Yay injecting all the things! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also using temp dirs rather than |
||
return mainViper, nil | ||
}, | ||
retriever: nil, | ||
} | ||
} | ||
|
||
func TestAddInvalidDelegationName(t *testing.T) { | ||
// Cleanup after test | ||
defer os.RemoveAll(testTrustDir) | ||
func TestPurgeDelegationKeys(t *testing.T) { | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
|
||
cmdr := setup(tmpDir) | ||
cmd := cmdr.GetCommand() | ||
err = cmdr.delegationPurgeKeys(cmd, []string{}) | ||
require.Error(t, err) | ||
|
||
err = cmdr.delegationPurgeKeys(cmd, []string{"gun"}) | ||
require.Error(t, err) | ||
|
||
cmdr.keyIDs = []string{"abc"} | ||
err = cmdr.delegationPurgeKeys(cmd, []string{"gun"}) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestAddInvalidDelegationName(t *testing.T) { | ||
// Setup certificate | ||
tempFile, err := ioutil.TempFile("/tmp", "pemfile") | ||
require.NoError(t, err) | ||
|
@@ -41,17 +54,17 @@ func TestAddInvalidDelegationName(t *testing.T) { | |
defer os.Remove(tempFile.Name()) | ||
|
||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid delegation name (should be prefixed by "targets/") | ||
err = commander.delegationAdd(commander.GetCommand(), []string{"gun", "INVALID_NAME", tempFile.Name()}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestAddInvalidDelegationCert(t *testing.T) { | ||
// Cleanup after test | ||
defer os.RemoveAll(testTrustDir) | ||
|
||
// Setup certificate | ||
tempFile, err := ioutil.TempFile("/tmp", "pemfile") | ||
require.NoError(t, err) | ||
|
@@ -62,17 +75,17 @@ func TestAddInvalidDelegationCert(t *testing.T) { | |
defer os.Remove(tempFile.Name()) | ||
|
||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to expired cert | ||
err = commander.delegationAdd(commander.GetCommand(), []string{"gun", "targets/delegation", tempFile.Name(), "--paths", "path"}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestAddInvalidShortPubkeyCert(t *testing.T) { | ||
// Cleanup after test | ||
defer os.RemoveAll(testTrustDir) | ||
|
||
// Setup certificate | ||
tempFile, err := ioutil.TempFile("/tmp", "pemfile") | ||
require.NoError(t, err) | ||
|
@@ -83,61 +96,73 @@ func TestAddInvalidShortPubkeyCert(t *testing.T) { | |
defer os.Remove(tempFile.Name()) | ||
|
||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to short RSA key | ||
err = commander.delegationAdd(commander.GetCommand(), []string{"gun", "targets/delegation", tempFile.Name(), "--paths", "path"}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestRemoveInvalidDelegationName(t *testing.T) { | ||
// Cleanup after test | ||
defer os.RemoveAll(testTrustDir) | ||
|
||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid delegation name (should be prefixed by "targets/") | ||
err := commander.delegationRemove(commander.GetCommand(), []string{"gun", "INVALID_NAME", "fake_key_id1", "fake_key_id2"}) | ||
err = commander.delegationRemove(commander.GetCommand(), []string{"gun", "INVALID_NAME", "fake_key_id1", "fake_key_id2"}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestRemoveAllInvalidDelegationName(t *testing.T) { | ||
// Cleanup after test | ||
defer os.RemoveAll(testTrustDir) | ||
|
||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid delegation name (should be prefixed by "targets/") | ||
err := commander.delegationRemove(commander.GetCommand(), []string{"gun", "INVALID_NAME"}) | ||
err = commander.delegationRemove(commander.GetCommand(), []string{"gun", "INVALID_NAME"}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestAddInvalidNumArgs(t *testing.T) { | ||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid number of args (2 instead of 3) | ||
err := commander.delegationAdd(commander.GetCommand(), []string{"not", "enough"}) | ||
err = commander.delegationAdd(commander.GetCommand(), []string{"not", "enough"}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestListInvalidNumArgs(t *testing.T) { | ||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid number of args (0 instead of 1) | ||
err := commander.delegationsList(commander.GetCommand(), []string{}) | ||
err = commander.delegationsList(commander.GetCommand(), []string{}) | ||
require.Error(t, err) | ||
} | ||
|
||
func TestRemoveInvalidNumArgs(t *testing.T) { | ||
// Setup commander | ||
commander := setup() | ||
tmpDir, err := ioutil.TempDir("/tmp", "notary-cmd-test-") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tmpDir) | ||
commander := setup(tmpDir) | ||
|
||
// Should error due to invalid number of args (1 instead of 2) | ||
err := commander.delegationRemove(commander.GetCommand(), []string{"notenough"}) | ||
err = commander.delegationRemove(commander.GetCommand(), []string{"notenough"}) | ||
require.Error(t, err) | ||
} | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is never getting exercised, which is weird because
cmd/notary/integration_test.go
'sTestPurge
should exercise this bit of code.In
applyChangelist
, where we switch based on whether the scope is a delegation (L43) I think we also have to change that line to beisDel := data.IsDelegation(c.Scope()) || data.IsWildDelegation(c.Scope())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, you're absolutely right, and that's making me wonder why the test in cmd/notary/delegations_test.go is even passing.
Going to add some more checks to that test to try and make it fail, then will update this and see if it passes again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see now. I'm calling the purge command but not publish so it's not actually applying the change. I must have got sidetracked half way through the test and forgotten to come back to it.