Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38b6dad

Browse files
committed
Security
1 parent 9272c01 commit 38b6dad

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

coderd/coderdtest/swaggerparser.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import (
1616
)
1717

1818
type SwaggerComment struct {
19-
summary string
20-
id string
21-
tags string
19+
summary string
20+
id string
21+
security string
22+
tags string
2223

2324
method string
2425
router string
@@ -93,6 +94,9 @@ func parseSwaggerComment(commentGroup *ast.CommentGroup) SwaggerComment {
9394
} else if strings.HasPrefix(text, "@Tags ") {
9495
args := strings.SplitN(text, " ", 2)
9596
c.tags = args[1]
97+
} else if strings.HasPrefix(text, "@Security ") {
98+
args := strings.SplitN(text, " ", 2)
99+
c.security = args[1]
96100
}
97101
}
98102
return c
@@ -118,6 +122,8 @@ func VerifySwaggerDefinitions(t *testing.T, router chi.Router, swaggerComments [
118122
assertSuccessOrFailureDefined(t, *c)
119123
assertRequiredAnnotations(t, *c)
120124
assertGoCommentFirst(t, *c)
125+
assertURLParamsDefined(t, *c)
126+
assertSecurityDefined(t, *c)
121127
})
122128
return nil
123129
})
@@ -170,3 +176,15 @@ func assertGoCommentFirst(t *testing.T, comment SwaggerComment) {
170176
}
171177
}
172178
}
179+
180+
func assertURLParamsDefined(t *testing.T, comment SwaggerComment) {
181+
}
182+
183+
func assertSecurityDefined(t *testing.T, comment SwaggerComment) {
184+
if comment.router == "/updatecheck" ||
185+
comment.router == "/buildinfo" ||
186+
comment.router == "/" {
187+
return // endpoints do not require authorization
188+
}
189+
assert.Equal(t, "CoderSessionToken", comment.security, "@Security must be equal CoderSessionToken")
190+
}

0 commit comments

Comments
 (0)