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

auto-publish for witness #912

Merged
merged 1 commit into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion cmd/notary/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,8 @@ func TestPurge(t *testing.T) {
// 9. witness the delegation
// 10. list targets and ensure target is visible again
// 11. witness an invalid role and check for error on publish
// 12. check non-targets base roles all fail
// 13. test auto-publish functionality
func TestWitness(t *testing.T) {
setUp(t)

Expand All @@ -1498,7 +1500,7 @@ func TestWitness(t *testing.T) {
tempFile2, err := ioutil.TempFile("", "pemfile2")
require.NoError(t, err)

cert2, privKey2, _ := generateCertPrivKeyPair(t, "gun", data.ECDSAKey)
cert2, privKey2, keyID2 := generateCertPrivKeyPair(t, "gun", data.ECDSAKey)
_, err = tempFile2.Write(utils.CertToPEM(cert2))
require.NoError(t, err)
tempFile2.Close()
Expand Down Expand Up @@ -1613,6 +1615,34 @@ func TestWitness(t *testing.T) {
_, err = runCommand(t, tempDir, "-s", server.URL, "publish", "gun")
require.Error(t, err)
}

// 13. test auto-publish functionality (just for witness)

// purge the old staged witness
_, err = runCommand(t, tempDir, "status", "gun", "--reset")
require.NoError(t, err)

// remove key2 and add back key1
_, err = runCommand(t, tempDir, "delegation", "add", "gun", delgName, tempFile.Name(), "--all-paths")
require.NoError(t, err)
_, err = runCommand(t, tempDir, "delegation", "remove", "gun", delgName, keyID2)
require.NoError(t, err)
_, err = runCommand(t, tempDir, "-s", server.URL, "publish", "gun")
require.NoError(t, err)

// the role now won't show its target because it's invalid
output, err = runCommand(t, tempDir, "-s", server.URL, "list", "gun")
require.NoError(t, err)
require.NotContains(t, output, targetName)
require.NotContains(t, output, targetHash)

// auto-publish with witness, check that the target is back
_, err = runCommand(t, tempDir, "-s", server.URL, "witness", "-p", "gun", delgName)
require.NoError(t, err)
output, err = runCommand(t, tempDir, "-s", server.URL, "list", "gun")
require.NoError(t, err)
require.Contains(t, output, targetName)
require.Contains(t, output, targetHash)
}

func generateCertPrivKeyPair(t *testing.T, gun, keyAlgorithm string) (*x509.Certificate, data.PrivateKey, string) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/notary/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (t *tufCommander) AddToCommand(cmd *cobra.Command) {
cmd.AddCommand(cmdTUFVerify)

cmdWitness := cmdWitnessTemplate.ToCommand(t.tufWitness)
cmdWitness.Flags().BoolVarP(&t.autoPublish, "publish", "p", false, htAutoPublish)
cmd.AddCommand(cmdWitness)

cmdTUFDeleteGUN := cmdTUFDeleteTemplate.ToCommand(t.tufDeleteGUN)
Expand Down Expand Up @@ -203,7 +204,7 @@ func (t *tufCommander) tufWitness(cmd *cobra.Command, args []string) error {
strings.Join(success, "\n\t- "),
)

return nil
return maybeAutoPublish(cmd, t.autoPublish, gun, config, t.retriever)
}

func (t *tufCommander) tufAddByHash(cmd *cobra.Command, args []string) error {
Expand Down