@@ -155,6 +155,183 @@ func TestProof(t *testing.T) {
155155 })
156156}
157157
158+ func TestInvalidInterfaceTypeShouldNotPanic (t * testing.T ) {
159+ t .Run ("does not panic if type is not a string" , func (t * testing.T ) {
160+ defer func () {
161+ r := recover ()
162+ require .Nil (t , r )
163+ }()
164+ _ , err := NewProof (map [string ]interface {}{
165+ "type" : 123 ,
166+ "creator" : "didID" ,
167+ "verificationMethod" : "did:example:123456#key1" ,
168+ "created" : "2018-03-15T00:00:00Z" ,
169+ "domain" : "abc.com" ,
170+ "nonce" : "" ,
171+ "proofValue" : proofValueBase64 ,
172+ })
173+ require .NoError (t , err )
174+ })
175+
176+ t .Run ("does not panic if created is not a string" , func (t * testing.T ) {
177+ defer func () {
178+ r := recover ()
179+ require .Nil (t , r )
180+ }()
181+ _ , err := NewProof (map [string ]interface {}{
182+ "type" : "type" ,
183+ "creator" : "didID" ,
184+ "verificationMethod" : "did:example:123456#key1" ,
185+ "created" : 123 ,
186+ "domain" : "abc.com" ,
187+ "nonce" : "" ,
188+ "proofValue" : proofValueBase64 ,
189+ })
190+ require .Error (t , err )
191+ require .Contains (t , err .Error (), "parsing time" )
192+ })
193+
194+ t .Run ("does not panic if creator is not a string" , func (t * testing.T ) {
195+ defer func () {
196+ r := recover ()
197+ require .Nil (t , r )
198+ }()
199+ _ , err := NewProof (map [string ]interface {}{
200+ "type" : "type" ,
201+ "creator" : 123 ,
202+ "verificationMethod" : "did:example:123456#key1" ,
203+ "created" : "2018-03-15T00:00:00Z" ,
204+ "domain" : "abc.com" ,
205+ "nonce" : "" ,
206+ "proofValue" : proofValueBase64 ,
207+ })
208+ require .NoError (t , err )
209+ })
210+
211+ t .Run ("does not panic if verificationMethod is not a string" , func (t * testing.T ) {
212+ defer func () {
213+ r := recover ()
214+ require .Nil (t , r )
215+ }()
216+ _ , err := NewProof (map [string ]interface {}{
217+ "type" : "type" ,
218+ "creator" : "didID" ,
219+ "verificationMethod" : 123 ,
220+ "created" : "2018-03-15T00:00:00Z" ,
221+ "domain" : "abc.com" ,
222+ "nonce" : "" ,
223+ "proofValue" : proofValueBase64 ,
224+ })
225+ require .NoError (t , err )
226+ })
227+
228+ t .Run ("does not panic if proofValue is not a string" , func (t * testing.T ) {
229+ defer func () {
230+ r := recover ()
231+ require .Nil (t , r )
232+ }()
233+ _ , err := NewProof (map [string ]interface {}{
234+ "type" : "type" ,
235+ "creator" : "didID" ,
236+ "verificationMethod" : "did:example:123456#key1" ,
237+ "created" : "2018-03-15T00:00:00Z" ,
238+ "domain" : "abc.com" ,
239+ "nonce" : "" ,
240+ "proofValue" : 123 ,
241+ })
242+ require .Error (t , err )
243+ require .Contains (t , err .Error (), "signature is not defined" )
244+ })
245+
246+ t .Run ("does not panic if jws is not a string" , func (t * testing.T ) {
247+ defer func () {
248+ r := recover ()
249+ require .Nil (t , r )
250+ }()
251+ _ , err := NewProof (map [string ]interface {}{
252+ "type" : "type" ,
253+ "creator" : "didID" ,
254+ "verificationMethod" : "did:example:123456#key1" ,
255+ "created" : "2018-03-15T00:00:00Z" ,
256+ "domain" : "abc.com" ,
257+ "nonce" : "" ,
258+ "jws" : 123 ,
259+ })
260+ require .Error (t , err )
261+ require .Contains (t , err .Error (), "signature is not defined" )
262+ })
263+
264+ t .Run ("does not panic if proofPurpose is not a string" , func (t * testing.T ) {
265+ defer func () {
266+ r := recover ()
267+ require .Nil (t , r )
268+ }()
269+ _ , err := NewProof (map [string ]interface {}{
270+ "type" : "type" ,
271+ "creator" : "didID" ,
272+ "verificationMethod" : "did:example:123456#key1" ,
273+ "created" : "2018-03-15T00:00:00Z" ,
274+ "domain" : "abc.com" ,
275+ "nonce" : "" ,
276+ "proofValue" : proofValueBase64 ,
277+ "proofPurpose" : 123 ,
278+ })
279+ require .NoError (t , err )
280+ })
281+
282+ t .Run ("does not panic if domain is not a string" , func (t * testing.T ) {
283+ defer func () {
284+ r := recover ()
285+ require .Nil (t , r )
286+ }()
287+ _ , err := NewProof (map [string ]interface {}{
288+ "type" : "type" ,
289+ "creator" : "didID" ,
290+ "verificationMethod" : "did:example:123456#key1" ,
291+ "created" : "2018-03-15T00:00:00Z" ,
292+ "domain" : 123 ,
293+ "nonce" : "" ,
294+ "proofValue" : proofValueBase64 ,
295+ })
296+ require .NoError (t , err )
297+ })
298+
299+ t .Run ("does not panic if nonce is not a string" , func (t * testing.T ) {
300+ defer func () {
301+ r := recover ()
302+ require .Nil (t , r )
303+ }()
304+ _ , err := NewProof (map [string ]interface {}{
305+ "type" : "type" ,
306+ "creator" : "didID" ,
307+ "verificationMethod" : "did:example:123456#key1" ,
308+ "created" : "2018-03-15T00:00:00Z" ,
309+ "domain" : "abc.com" ,
310+ "nonce" : 123 ,
311+ "proofValue" : proofValueBase64 ,
312+ })
313+ require .NoError (t , err )
314+ })
315+
316+ t .Run ("does not panic if challenge is not a string" , func (t * testing.T ) {
317+ defer func () {
318+ r := recover ()
319+ require .Nil (t , r )
320+ }()
321+ _ , err := NewProof (map [string ]interface {}{
322+ "type" : "type" ,
323+ "creator" : "didID" ,
324+ "verificationMethod" : "did:example:123456#key1" ,
325+ "created" : "2018-03-15T00:00:00Z" ,
326+ "domain" : "abc.com" ,
327+ "nonce" : "" ,
328+ "proofValue" : proofValueBase64 ,
329+ "challenge" : 123 ,
330+ })
331+ require .NoError (t , err )
332+ })
333+ }
334+
158335func TestInvalidProofValue (t * testing.T ) {
159336 // invalid proof value
160337 p , err := NewProof (map [string ]interface {}{
0 commit comments