diff --git a/dumper/file/file_test.go b/dumper/file/file_test.go new file mode 100644 index 0000000..3b70531 --- /dev/null +++ b/dumper/file/file_test.go @@ -0,0 +1,60 @@ +package file + +import ( + "io/ioutil" + "os" + "testing" + + "github.com/ldez/traefik-certs-dumper/v2/dumper" + "github.com/stretchr/testify/require" +) + +func TestDump(t *testing.T) { + testCases := []struct { + desc string + acmeFile string + version string + }{ + { + desc: "should skip EOF error", + acmeFile: "./fixtures/acme-empty.json", + }, + { + desc: "should dump traefik v1 file content", + acmeFile: "./fixtures/acme-v1.json", + }, + { + desc: "should dump traefik v2 file content", + acmeFile: "./fixtures/acme-v2.json", + version: "v2", + }, + } + + for _, test := range testCases { + test := test + t.Run(test.desc, func(t *testing.T) { + t.Parallel() + + dir, err := ioutil.TempDir("", "traefik-cert-dumper") + require.NoError(t, err) + defer func() { _ = os.RemoveAll(dir) }() + + cfg := &dumper.BaseConfig{ + DumpPath: dir, + CrtInfo: dumper.FileInfo{ + Name: "certificate", + Ext: ".crt", + }, + KeyInfo: dumper.FileInfo{ + Name: "privatekey", + Ext: ".key", + }, + Clean: true, + Version: test.version, + } + + err = Dump(test.acmeFile, cfg) + require.NoError(t, err) + }) + } +} diff --git a/dumper/file/fixtures/acme-empty.json b/dumper/file/fixtures/acme-empty.json new file mode 100644 index 0000000..e69de29 diff --git a/dumper/file/fixtures/acme-v1.json b/dumper/file/fixtures/acme-v1.json new file mode 100644 index 0000000..ea3261a --- /dev/null +++ b/dumper/file/fixtures/acme-v1.json @@ -0,0 +1,12 @@ +{ + "Certificates": [ + { + "domain": { + "main": "test.example.com" + }, + "certificate": "Q2VydGlmaWNhdGU=", + "key": "Q2VydGlmaWNhdGUgS2V5", + "Store": "default" + } + ] +} diff --git a/dumper/file/fixtures/acme-v2.json b/dumper/file/fixtures/acme-v2.json new file mode 100644 index 0000000..38a1f34 --- /dev/null +++ b/dumper/file/fixtures/acme-v2.json @@ -0,0 +1,36 @@ +{ + "default": { + "Account": { + "Email": "test@email.com", + "Registration": { + "body": { + "status": "valid", + "contact": [ + "mailto:test@email.com" + ] + }, + "uri": "https://acme-v02.api.letsencrypt.org/acme/acct/12345678" + }, + "PrivateKey": "Q2VydGlmaWNhdGUgS2V5", + "KeyType": "4096" + }, + "Certificates": [ + { + "domain": { + "main": "my.domain.com" + }, + "certificate": "Q2VydGlmaWNhdGU=", + "key": "Q2VydGlmaWNhdGUgS2V5", + "Store": "default" + }, + { + "domain": { + "main": "my.domain2.com" + }, + "certificate": "Q2VydGlmaWNhdGU=", + "key": "Q2VydGlmaWNhdGUgS2V5", + "Store": "default" + } + ] + } +} \ No newline at end of file