Skip to content

Commit

Permalink
allow _ in subject name (#3501)
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst authored Oct 18, 2024
1 parent 4e53223 commit c8a740d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion docs/_static/vdr/v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ components:
properties:
subject:
type: string
description: controls the DID subject to which all created DIDs are bound. If not given, a uuid is generated and returned.
description: |
controls the DID subject to which all created DIDs are bound. If not given, a uuid is generated and returned.
The subject must follow the pattern [a-zA-Z0-9._-]+
keys:
$ref: '#/components/schemas/KeyCreationOptions'
DIDDocument:
Expand Down
2 changes: 1 addition & 1 deletion vdr/didsubject/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
)

// subjectPattern is a regular expression for checking whether a subject follows the allowed pattern; a-z, 0-9, -, _, . (case insensitive)
var subjectPattern = regexp.MustCompile(`^[a-zA-Z0-9.-]+$`)
var subjectPattern = regexp.MustCompile(`^[a-zA-Z0-9._-]+$`)

var _ Manager = (*SqlManager)(nil)

Expand Down
14 changes: 12 additions & 2 deletions vdr/didsubject/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ func TestManager_Create(t *testing.T) {

require.Error(t, err)
assert.ErrorIs(t, err, ErrSubjectValidation)
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9.-]+$)")
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9._-]+$)")
})
t.Run("contains allowed characters", func(t *testing.T) {
db := testDB(t)
m := SqlManager{DB: db, MethodManagers: map[string]MethodManager{
"example": testMethod{},
}}

_, _, err := m.Create(audit.TestContext(), DefaultCreationOptions().With(SubjectCreationOption{Subject: "subject_with-special.characters"}))

assert.NoError(t, err)
})
t.Run("contains illegal character (space)", func(t *testing.T) {
db := testDB(t)
Expand All @@ -182,7 +192,7 @@ func TestManager_Create(t *testing.T) {

require.Error(t, err)
assert.ErrorIs(t, err, ErrSubjectValidation)
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9.-]+$)")
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9._-]+$)")
})
})
}
Expand Down

0 comments on commit c8a740d

Please sign in to comment.