Skip to content

Commit c8a740d

Browse files
allow _ in subject name (#3501)
1 parent 4e53223 commit c8a740d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

docs/_static/vdr/v2.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,9 @@ components:
482482
properties:
483483
subject:
484484
type: string
485-
description: controls the DID subject to which all created DIDs are bound. If not given, a uuid is generated and returned.
485+
description: |
486+
controls the DID subject to which all created DIDs are bound. If not given, a uuid is generated and returned.
487+
The subject must follow the pattern [a-zA-Z0-9._-]+
486488
keys:
487489
$ref: '#/components/schemas/KeyCreationOptions'
488490
DIDDocument:

vdr/didsubject/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
)
4343

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

4747
var _ Manager = (*SqlManager)(nil)
4848

vdr/didsubject/manager_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,17 @@ func TestManager_Create(t *testing.T) {
170170

171171
require.Error(t, err)
172172
assert.ErrorIs(t, err, ErrSubjectValidation)
173-
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9.-]+$)")
173+
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9._-]+$)")
174+
})
175+
t.Run("contains allowed characters", func(t *testing.T) {
176+
db := testDB(t)
177+
m := SqlManager{DB: db, MethodManagers: map[string]MethodManager{
178+
"example": testMethod{},
179+
}}
180+
181+
_, _, err := m.Create(audit.TestContext(), DefaultCreationOptions().With(SubjectCreationOption{Subject: "subject_with-special.characters"}))
182+
183+
assert.NoError(t, err)
174184
})
175185
t.Run("contains illegal character (space)", func(t *testing.T) {
176186
db := testDB(t)
@@ -182,7 +192,7 @@ func TestManager_Create(t *testing.T) {
182192

183193
require.Error(t, err)
184194
assert.ErrorIs(t, err, ErrSubjectValidation)
185-
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9.-]+$)")
195+
assert.ErrorContains(t, err, "invalid subject (must follow pattern: ^[a-zA-Z0-9._-]+$)")
186196
})
187197
})
188198
}

0 commit comments

Comments
 (0)