aboutsummaryrefslogtreecommitdiff
path: root/cli_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-06-22 16:35:47 +0700
committerShulhan <ms@kilabit.info>2024-06-22 17:21:56 +0700
commitdbe4f9722bbd63f685b36606abbfd97cbf1dfb10 (patch)
treeb1eb61d3f75aa60f65541ba51408d3d4a708b48d /cli_test.go
parent4eaf76a096a0ba8ba5e687ede23c1dafd9064358 (diff)
downloadgotp-dbe4f9722bbd63f685b36606abbfd97cbf1dfb10.tar.xz
all: implement command "export"
The "export" command export all issuers to file or standard output, $ gotp export <FORMAT> [FILE] List of known supported FORMAT is: uri. If FILE is not defined it will print to standard output. The list of exported issuers are printed in order of its label.
Diffstat (limited to 'cli_test.go')
-rw-r--r--cli_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/cli_test.go b/cli_test.go
index ef6a07c..485cad5 100644
--- a/cli_test.go
+++ b/cli_test.go
@@ -10,6 +10,7 @@ import (
"io/fs"
"os"
"path/filepath"
+ "strings"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
@@ -90,6 +91,37 @@ test = SHA1:x:6:30:
}
}
+func TestCli_Export(t *testing.T) {
+ var (
+ tdata *test.Data
+ err error
+ )
+
+ tdata, err = test.LoadData(`testdata/cli_Export_test.txt`)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var cli = &Cli{
+ cfg: &config{
+ Issuers: map[string]string{
+ `test l@bel`: `SHA1:s3cr3t:6:30:IssuerName`,
+ },
+ },
+ }
+
+ var sb = strings.Builder{}
+
+ err = cli.Export(&sb, formatNameURI)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var exp = string(tdata.Output[`uri`])
+
+ test.Assert(t, `Export: uri`, exp, sb.String())
+}
+
func TestCli_SetPrivateKey(t *testing.T) {
var (
tdata *test.Data
@@ -265,6 +297,10 @@ func TestCli_withPassphrase(t *testing.T) {
testAddWithPassphrase(t, tdata, cli)
})
+ t.Run(`Export`, func(t *testing.T) {
+ testExportWithPassphrase(t, tdata, cli)
+ })
+
t.Run(`Generate`, func(t *testing.T) {
testGenerateWithPassphrase(t, tdata, cli)
})
@@ -330,6 +366,24 @@ func testAddWithPassphrase(t *testing.T, tdata *test.Data, cli *Cli) {
mockTermrw.BufRead.Reset()
}
+func testExportWithPassphrase(t *testing.T, tdata *test.Data, cli *Cli) {
+ var pass = string(tdata.Input[`gotp.pass`]) + "\r\n"
+ mockTermrw.BufRead.WriteString(pass)
+
+ t.Cleanup(mockTermrw.BufRead.Reset)
+
+ var got = strings.Builder{}
+
+ var err = cli.Export(&got, formatNameURI)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var exp = string(tdata.Output[`gotp.conf:export`])
+
+ test.Assert(t, `testExportWithPassphrase`, exp, got.String())
+}
+
func testGenerateWithPassphrase(t *testing.T, tdata *test.Data, cli *Cli) {
type testCase struct {
label string