@@ -74,7 +74,7 @@ func Test_GetEvidence_invalid_format(t *testing.T) {
74
74
assert .Equal (t , expected , p .GetEvidence (in ))
75
75
}
76
76
77
- func Test_GetEvidence (t * testing.T ) {
77
+ func Test_GetEvidence_No_Options (t * testing.T ) {
78
78
inblob := []byte (validNonceStr )
79
79
in := & compositor.EvidenceIn {
80
80
ContentType : string (mediaType ),
@@ -97,3 +97,58 @@ func Test_GetEvidence(t *testing.T) {
97
97
98
98
assert .Equal (t , expected , p .GetEvidence (in ))
99
99
}
100
+
101
+ func TestGetEvidence_With_Invalid_Options (t * testing.T ) {
102
+ tests := []struct {name , params , msg string } {
103
+ {"privilege level not integer" , "{\" privilege_level\" : \" invalid\" }" ,
104
+ "privilege_level invalid is invalid" },
105
+ {"privilege level less than zero" , "{\" privilege_level\" : \" -20\" }" ,
106
+ "privilege_level -20 is invalid" },
107
+ {"invalid json" , "{\" privilege_level\" }" ,
108
+ "failed to parse {\" privilege_level\" }: invalid character '}' after object key" },
109
+ }
110
+ for _ , tt := range tests {
111
+ t .Run (tt .name , func (t * testing.T ) {
112
+ inblob := []byte (validNonceStr )
113
+ in := & compositor.EvidenceIn {
114
+ ContentType : string (mediaType ),
115
+ Nonce : inblob ,
116
+ Options : tt .params ,
117
+ }
118
+
119
+ expected := & compositor.EvidenceOut {
120
+ Status : & compositor.Status {
121
+ Result : false ,
122
+ Error : tt .msg ,
123
+ },
124
+ }
125
+
126
+ assert .Equal (t , expected , p .GetEvidence (in ))
127
+ })
128
+ }
129
+ }
130
+
131
+ func Test_GetEvidence_With_Valid_Privilege_level (t * testing.T ) {
132
+ inblob := []byte (validNonceStr )
133
+ in := & compositor.EvidenceIn {
134
+ ContentType : string (mediaType ),
135
+ Nonce : inblob ,
136
+ Options : "{\" privilege_level\" : \" 1\" }" ,
137
+ }
138
+
139
+ expectedOutblob := fmt .Sprintf ("privlevel: 1\n inblob: %s" , hex .EncodeToString (inblob ))
140
+ out := & tokens.TSMReport {
141
+ Provider : "fake\n " ,
142
+ OutBlob : []byte (expectedOutblob ),
143
+ AuxBlob : []byte ("auxblob" ),
144
+ }
145
+
146
+ outEncoded , _ := out .ToJSON ()
147
+
148
+ expected := & compositor.EvidenceOut {
149
+ Status : statusSucceeded ,
150
+ Evidence : outEncoded ,
151
+ }
152
+
153
+ assert .Equal (t , expected , p .GetEvidence (in ))
154
+ }
0 commit comments