auth: add Validate() and deprecate Validator{} (#272)

This commit is contained in:
Alessandro Ros
2023-05-07 19:34:20 +02:00
committed by GitHub
parent 2170ef4b00
commit 7c67221494
11 changed files with 280 additions and 106 deletions

View File

@@ -1045,17 +1045,17 @@ func TestServerSessionTeardown(t *testing.T) {
}
func TestServerAuth(t *testing.T) {
authValidator := auth.NewValidator("myuser", "mypass", nil)
nonce := auth.GenerateNonce()
s := &Server{
Handler: &testServerHandler{
onAnnounce: func(ctx *ServerHandlerOnAnnounceCtx) (*base.Response, error) {
err := authValidator.ValidateRequest(ctx.Request, nil)
err := auth.Validate(ctx.Request, "myuser", "mypass", nil, nil, "IPCAM", nonce)
if err != nil {
return &base.Response{
StatusCode: base.StatusUnauthorized,
Header: base.Header{
"WWW-Authenticate": authValidator.Header(),
"WWW-Authenticate": auth.GenerateWWWAuthenticate(nil, "IPCAM", nonce),
},
}, nil
}