Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed error messages of trust policy #326

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion verifier/trustpolicy/trustpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func validateTrustedIdentities(statement TrustPolicy) error {
}
dn, err := pkix.ParseDistinguishedName(identityValue)
if err != nil {
return err
return fmt.Errorf("trust policy statement %q has trusted identity %q with invalid identity value: %w", statement.Name, identity, err)
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
}
parsedDNs = append(parsedDNs, parsedDN{RawString: identity, ParsedMap: dn})
}
Expand Down
8 changes: 4 additions & 4 deletions verifier/trustpolicy/trustpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
policyStatement.TrustedIdentities = []string{invalidDN}
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
err = policyDoc.Validate()
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" {
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" {
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
}

Expand All @@ -116,7 +116,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
policyStatement.TrustedIdentities = []string{invalidDN}
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
err = policyDoc.Validate()
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" {
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" {
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
}

Expand All @@ -127,7 +127,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
policyStatement.TrustedIdentities = []string{invalidDN}
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
err = policyDoc.Validate()
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" {
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" {
t.Fatalf("invalid x509.subject identity should return error. Error : %q", err)
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func TestValidateTrustedIdentities(t *testing.T) {
policyStatement.TrustedIdentities = []string{multiValduedRDN}
policyDoc.TrustPolicies = []TrustPolicy{policyStatement}
err = policyDoc.Validate()
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" {
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" {
t.Fatalf("multi-valued RDN should return error. Error : %q", err)
}
}
Expand Down