Skip to content

Commit 983e97d

Browse files
author
Patrick Zheng
authored
fix: fixed error messages of trust policy (#326)
A quick PR to fix error messages of trust policy. Signed-off-by: Patrick Zheng <[email protected]>
1 parent a973c8b commit 983e97d

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

verifier/trustpolicy/trustpolicy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func validateTrustedIdentities(statement TrustPolicy) error {
436436
}
437437
dn, err := pkix.ParseDistinguishedName(identityValue)
438438
if err != nil {
439-
return err
439+
return fmt.Errorf("trust policy statement %q has trusted identity %q with invalid identity value: %w", statement.Name, identity, err)
440440
}
441441
parsedDNs = append(parsedDNs, parsedDN{RawString: identity, ParsedMap: dn})
442442
}

verifier/trustpolicy/trustpolicy_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
105105
policyStatement.TrustedIdentities = []string{invalidDN}
106106
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
107107
err = policyDoc.Validate()
108-
if err == nil || err.Error() != "parsing distinguished name (DN) \",,,\" failed with err: incomplete type, value pair. A valid DN must contain 'C', 'ST', and 'O' RDN attributes at a minimum, and follow RFC 4514 standard" {
108+
if err == nil || err.Error() != "trust policy statement \"test-statement-name\" has trusted identity \"x509.subject:,,,\" with invalid identity value: parsing distinguished name (DN) \",,,\" failed with err: incomplete type, value pair. A valid DN must contain 'C', 'ST', and 'O' RDN attributes at a minimum, and follow RFC 4514 standard" {
109109
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
110110
}
111111

@@ -116,7 +116,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
116116
policyStatement.TrustedIdentities = []string{invalidDN}
117117
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
118118
err = policyDoc.Validate()
119-
if err == nil || err.Error() != "distinguished name (DN) \"C=US,C=IN\" has duplicate RDN attribute for \"C\", DN can only have unique RDN attributes" {
119+
if err == nil || err.Error() != "trust policy statement \"test-statement-name\" has trusted identity \"x509.subject:C=US,C=IN\" with invalid identity value: distinguished name (DN) \"C=US,C=IN\" has duplicate RDN attribute for \"C\", DN can only have unique RDN attributes" {
120120
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
121121
}
122122

@@ -127,7 +127,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
127127
policyStatement.TrustedIdentities = []string{invalidDN}
128128
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
129129
err = policyDoc.Validate()
130-
if err == nil || err.Error() != "distinguished name (DN) \"C=US,ST=WA\" has no mandatory RDN attribute for \"O\", it must contain 'C', 'ST', and 'O' RDN attributes at a minimum" {
130+
if err == nil || err.Error() != "trust policy statement \"test-statement-name\" has trusted identity \"x509.subject:C=US,ST=WA\" with invalid identity value: distinguished name (DN) \"C=US,ST=WA\" has no mandatory RDN attribute for \"O\", it must contain 'C', 'ST', and 'O' RDN attributes at a minimum" {
131131
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
132132
}
133133

@@ -174,7 +174,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
174174
policyStatement.TrustedIdentities = []string{multiValduedRDN}
175175
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
176176
err = policyDoc.Validate()
177-
if err == nil || err.Error() != "distinguished name (DN) \"C=US+ST=WA,O=MyOrg\" has multi-valued RDN attributes, remove multi-valued RDN attributes as they are not supported" {
177+
if err == nil || err.Error() != "trust policy statement \"test-statement-name\" has trusted identity \"x509.subject:C=US+ST=WA,O=MyOrg\" with invalid identity value: distinguished name (DN) \"C=US+ST=WA,O=MyOrg\" has multi-valued RDN attributes, remove multi-valued RDN attributes as they are not supported" {
178178
t.Fatalf("multi-valued RDN should return error. Error : %q", err)
179179
}
180180
}

0 commit comments

Comments
 (0)