From aedc3c206dd997c6dd96ce53a807b0b6ae635b3c Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 6 Oct 2023 16:35:12 +0700 Subject: all: implement command "get" The "get" command get and print the issuer by its LABEL. This will print the issuer secret, unencrypted. --- cli_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'cli_test.go') diff --git a/cli_test.go b/cli_test.go index 8d0218c..bf15eec 100644 --- a/cli_test.go +++ b/cli_test.go @@ -7,6 +7,7 @@ import ( "bytes" "fmt" "os" + "path/filepath" "testing" "github.com/shuLhan/share/lib/test" @@ -233,3 +234,47 @@ func TestCli_SetPrivateKey(t *testing.T) { rawConfig = tdata.Input[`config.ini`] test.Assert(t, `RemovePrivateKey`, string(rawConfig), string(gotConfig)) } + +func TestCli_ViewEncrypted(t *testing.T) { + var ( + configDir = t.TempDir() + + cli *Cli + err error + ) + + cli, err = NewCli(configDir) + if err != nil { + t.Fatal(err) + } + + var privateKeyFile = filepath.Join(`testdata`, `keys`, `rsa-openssh.pem`) + + err = cli.SetPrivateKey(privateKeyFile) + if err != nil { + t.Fatal(err) + } + + var issA *Issuer + + issA, err = NewIssuer(`testA`, `SHA1:TESTA`, nil) + if err != nil { + t.Fatal(err) + } + + err = cli.Add(issA) + if err != nil { + t.Fatal(err) + } + + var gotIssA *Issuer + + gotIssA, err = cli.Get(`testA`) + if err != nil { + t.Fatal(err) + } + + // Reset the raw issuer value for comparison. + issA.raw = nil + test.Assert(t, `Get: testA`, issA, gotIssA) +} -- cgit v1.3