Skip to content

Commit

Permalink
Merge branch 'pull/14'
Browse files Browse the repository at this point in the history
* pull/14:
  main_test: Fix minor typeo in test name
  main_test: Use regexps to parse output from Run* functions
  • Loading branch information
Foxboron committed Jul 13, 2023
2 parents 1d5050a + 28d3304 commit b7fa344
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cmd/age-plugin-tpm/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"regexp"
"testing"

"github.com/foxboron/age-plugin-tpm/plugin"
Expand Down Expand Up @@ -65,15 +66,16 @@ func TestEncryptDecrypt(t *testing.T) {
if err := RunRecipientV1(&stdin, &stdout); err != nil {
t.Fatalf("Failed RunRecipientV1: %v", err)
}
// TODO: Better parsing
output := strings.TrimSpace(stdout.String())
lines := strings.Split(output, "\n")
wrappedKey = strings.TrimSpace(lines[1])
tag = strings.Split(lines[0], " ")[4]
sessionKey = strings.Split(lines[0], " ")[5]

match := regexp.
MustCompile(`(?m)-> recipient-stanza 0 tpm-ecc (.+?) (.+?)\n(.+?)\n-> done`).
FindStringSubmatch(stdout.String())

tag, sessionKey, wrappedKey = match[1], match[2], match[3]

})

t.Run("RunIdentitiyv1", func(t *testing.T) {
t.Run("RunIdentitiyV1", func(t *testing.T) {
var stdin bytes.Buffer
var stdout strings.Builder

Expand All @@ -91,10 +93,10 @@ func TestEncryptDecrypt(t *testing.T) {
t.Fatalf("Failed RunRecipientV1: %v", err)
}

// TODO: Better parsing
output := strings.TrimSpace(stdout.String())
output = strings.ReplaceAll(output, "-> file-key 0\n", "")
output = strings.ReplaceAll(output, "-> done", "")
output := regexp.
MustCompile(`(?m)-> file-key 0\n(.+?)\n-> done`).
FindStringSubmatch(stdout.String())[1]

out, err := b64Decode(output)
if err != nil {
t.Fatalf("b64Decode failed: %v", err)
Expand Down

0 comments on commit b7fa344

Please sign in to comment.