File: uri_test.go

package info (click to toggle)
golang-github-smallstep-crypto 0.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,800 kB
  • sloc: sh: 66; makefile: 50
file content (40 lines) | stat: -rw-r--r-- 1,320 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tpmkms

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func Test_parseNameURI(t *testing.T) {
	type args struct {
		nameURI string
	}
	tests := []struct {
		name    string
		args    args
		wantO   objectProperties
		wantErr bool
	}{
		{"ok/key-without-scheme", args{"key1"}, objectProperties{name: "key1"}, false},
		{"ok/key", args{"tpmkms:name=key1"}, objectProperties{name: "key1"}, false},
		{"ok/key-without-name-key", args{"tpmkms:key1"}, objectProperties{name: "key1"}, false},
		{"ok/key-without-name-key-with-other-properties", args{"tpmkms:key1;attest-by=ak1"}, objectProperties{name: "key1", attestBy: "ak1"}, false},
		{"ok/attested-key", args{"tpmkms:name=key2;attest-by=ak1;qualifying-data=61626364"}, objectProperties{name: "key2", attestBy: "ak1", qualifyingData: []byte{'a', 'b', 'c', 'd'}}, false},
		{"ok/ak", args{"tpmkms:name=ak1;ak=true"}, objectProperties{name: "ak1", ak: true}, false},
		{"fail/empty", args{""}, objectProperties{}, true},
		{"fail/wrong-scheme", args{nameURI: "tpmkmz:name=bla"}, objectProperties{}, true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotO, err := parseNameURI(tt.args.nameURI)
			if tt.wantErr {
				assert.Error(t, err)
				return
			}

			assert.NoError(t, err)
			assert.Equal(t, tt.wantO, gotO)
		})
	}
}