Skip to content

Commit 02649f6

Browse files
committed
test: add invalid tests
1 parent e336d77 commit 02649f6

6 files changed

Lines changed: 318 additions & 72 deletions

File tree

validator/datamodel/cbor_gen.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

validator/datamodel/errors.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package datamodel
22

33
type ErrorModel struct {
4-
Name string `cborgen:"name"`
5-
Message string `cborgen:"message"`
4+
ErrorName string `cborgen:"name"`
5+
Message string `cborgen:"message"`
6+
}
7+
8+
func (u ErrorModel) Name() string {
9+
return u.ErrorName
610
}
711

812
func (u ErrorModel) Error() string {

validator/errors.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ const UnavailableProofErrorName = "UnavailableProof"
1414

1515
func NewUnavailableProofError(p ucan.Link, cause error) vdm.ErrorModel {
1616
return vdm.ErrorModel{
17-
Name: UnavailableProofErrorName,
18-
Message: fmt.Sprintf("linked proof %s could not be resolved: %s", p.String(), cause.Error()),
17+
ErrorName: UnavailableProofErrorName,
18+
Message: fmt.Sprintf("linked proof %s could not be resolved: %s", p.String(), cause.Error()),
1919
}
2020
}
2121

2222
const DIDKeyResolutionErrorName = "DIDKeyResolutionError"
2323

2424
func NewDIDKeyResolutionError(d did.DID, cause error) vdm.ErrorModel {
2525
return vdm.ErrorModel{
26-
Name: DIDKeyResolutionErrorName,
27-
Message: fmt.Sprintf("unable to resolve %s key: %s", d.String(), cause.Error()),
26+
ErrorName: DIDKeyResolutionErrorName,
27+
Message: fmt.Sprintf("unable to resolve %s key: %s", d.String(), cause.Error()),
2828
}
2929
}
3030

@@ -38,26 +38,26 @@ func NewExpiredError(t ucan.Token) vdm.ErrorModel {
3838
name = "proof"
3939
}
4040
return vdm.ErrorModel{
41-
Name: ExpiredErrorName,
42-
Message: fmt.Sprintf("%s %s has expired on %s", name, t.Link(), time.Unix(int64(*t.Expiration()), 0).Format(time.RFC3339)),
41+
ErrorName: ExpiredErrorName,
42+
Message: fmt.Sprintf("%s %s has expired on %s", name, t.Link(), time.Unix(int64(*t.Expiration()), 0).Format(time.RFC3339)),
4343
}
4444
}
4545

4646
const TooEarlyErrorName = "TooEarly"
4747

4848
func NewTooEarlyError(t ucan.Delegation) vdm.ErrorModel {
4949
return vdm.ErrorModel{
50-
Name: ExpiredErrorName,
51-
Message: fmt.Sprintf("proof %s is not valid before %s", t.Link(), time.Unix(int64(*t.NotBefore()), 0).Format(time.RFC3339)),
50+
ErrorName: TooEarlyErrorName,
51+
Message: fmt.Sprintf("proof %s is not valid before %s", t.Link(), time.Unix(int64(*t.NotBefore()), 0).Format(time.RFC3339)),
5252
}
5353
}
5454

5555
const MalformedArgumentsErrorName = "MalformedArguments"
5656

5757
func NewMalformedArgumentsError(cmd ucan.Command, cause error) vdm.ErrorModel {
5858
return vdm.ErrorModel{
59-
Name: MalformedArgumentsErrorName,
60-
Message: fmt.Sprintf("malformed arguments for command %s: %s", cmd, cause.Error()),
59+
ErrorName: MalformedArgumentsErrorName,
60+
Message: fmt.Sprintf("malformed arguments for command %s: %s", cmd, cause.Error()),
6161
}
6262
}
6363

@@ -76,8 +76,8 @@ func NewInvalidSignatureError(token ucan.Token, verifier ucan.Verifier) vdm.Erro
7676
}, "\n")
7777
}
7878
return vdm.ErrorModel{
79-
Name: InvalidSignatureErrorName,
80-
Message: message,
79+
ErrorName: InvalidSignatureErrorName,
80+
Message: message,
8181
}
8282
}
8383

@@ -86,7 +86,7 @@ const UnverifiableSignatureErrorName = "UnverifiableSignature"
8686
func NewUnverifiableSignatureError(token ucan.Token, cause error) vdm.ErrorModel {
8787
issuer := token.Issuer().DID()
8888
return vdm.ErrorModel{
89-
Name: UnverifiableSignatureErrorName,
90-
Message: fmt.Sprintf("proof %s issued by %s cannot be verified: %s", token.Link(), issuer, cause.Error()),
89+
ErrorName: UnverifiableSignatureErrorName,
90+
Message: fmt.Sprintf("proof %s issued by %s cannot be verified: %s", token.Link(), issuer, cause.Error()),
9191
}
9292
}

0 commit comments

Comments
 (0)