mediamtx/internal/protocols/httpp/credentials_test.go
Alessandro Ros f97213ae6e
Some checks are pending
code_lint / golangci_lint (push) Waiting to run
code_lint / mod_tidy (push) Waiting to run
code_lint / api_docs (push) Waiting to run
code_test / test_64 (push) Waiting to run
code_test / test_32 (push) Waiting to run
code_test / test_e2e (push) Waiting to run
support passing JWTs through the password field (#4516)
This is safer than passing JWTs through query parameters, unfortunately support is limited.
2025-05-10 22:54:24 +02:00

65 lines
1.1 KiB
Go

package httpp
import (
"net/http"
"net/url"
"testing"
"github.com/bluenviron/mediamtx/internal/auth"
"github.com/stretchr/testify/require"
)
func TestCredentials(t *testing.T) {
t.Run("user and pass in basic", func(t *testing.T) {
h := &http.Request{
URL: &url.URL{},
Header: http.Header{
"Authorization": []string{
"Basic bXl1c2VyOm15cGFzcw==",
},
},
}
c := Credentials(h)
require.Equal(t, &auth.Credentials{
User: "myuser",
Pass: "mypass",
}, c)
})
t.Run("user and pass in bearer", func(t *testing.T) {
h := &http.Request{
URL: &url.URL{},
Header: http.Header{
"Authorization": []string{
"Bearer myuser:mypass",
},
},
}
c := Credentials(h)
require.Equal(t, &auth.Credentials{
User: "myuser",
Pass: "mypass",
}, c)
})
t.Run("token in bearer", func(t *testing.T) {
h := &http.Request{
URL: &url.URL{},
Header: http.Header{
"Authorization": []string{
"Bearer testing123",
},
},
}
c := Credentials(h)
require.Equal(t, &auth.Credentials{
Token: "testing123",
}, c)
})
}