Skip to content

Commit

Permalink
Add test case to repro delegation import panic
Browse files Browse the repository at this point in the history
Signed-off-by: Riyaz Faizullabhoy <[email protected]>
  • Loading branch information
riyazdf committed Dec 23, 2016
1 parent 4d1d838 commit e754a31
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cmd/notary/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2562,3 +2562,43 @@ func TestExportImportFlow(t *testing.T) {
require.Contains(t, targString, "gun: gun")
require.True(t, strings.Contains(snapString, "role: snapshot") || strings.Contains(snapString, "role: target"))
}

// Tests import/export keys with delegations, which don't require a gun
func TestDelegationKeyImportExport(t *testing.T) {
// -- setup --
setUp(t)

tempDir := tempDirWithConfig(t, "{}")
defer os.RemoveAll(tempDir)

tempExportedDir := tempDirWithConfig(t, "{}")
defer os.RemoveAll(tempDir)

tempImportingDir := tempDirWithConfig(t, "{}")
defer os.RemoveAll(tempDir)

// Setup key in a file for import
keyFile, err := ioutil.TempFile("", "pemfile")
require.NoError(t, err)
defer os.Remove(keyFile.Name())
privKey, err := utils.GenerateRSAKey(rand.Reader, 2048)
require.NoError(t, err)
pemBytes, err := utils.EncryptPrivateKey(privKey, "", "", "")
require.NoError(t, err)
nBytes, err := keyFile.Write(pemBytes)
require.NoError(t, err)
keyFile.Close()
require.Equal(t, len(pemBytes), nBytes)

// import the key
_, err = runCommand(t, tempDir, "key", "import", keyFile.Name(), "-r", "user")
require.NoError(t, err)

// export the key
_, err = runCommand(t, tempDir, "key", "export", "-o", filepath.Join(tempExportedDir, "exported"))
require.NoError(t, err)

// re-import the key from the exported store to a new tempDir
_, err = runCommand(t, tempImportingDir, "key", "import", filepath.Join(tempExportedDir, "exported"))
require.NoError(t, err)
}

0 comments on commit e754a31

Please sign in to comment.