Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
38 changes: 38 additions & 0 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright © 2025 Prabhjot Singh Sethi, All Rights reserved
// Author: Prabhjot Singh Sethi <prabhjot.sethi@gmail.com>

package auth

import (
"fmt"
"net/http"
"testing"
)

func Test_ErrorValidations(t *testing.T) {
r := &http.Request{
Header: http.Header{},
}
info := &AuthInfo{
Realm: "root",
UserName: "admin",
Email: "admin@example.com",
FullName: "Test Admin",
SessionID: "abc",
}
SetAuthInfoHeader(r, info)
fmt.Printf("Got - Encoded Auth Info: %s\n", r.Header[httpClientAuthContext][0])
if r.Header[httpClientAuthContext][0] != "eyJyZWFsbSI6InJvb3QiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJhZG1pbiIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5jb20iLCJuYW1lIjoiVGVzdCBBZG1pbiIsInNpZCI6ImFiYyJ9" {
t.Errorf("failed to set the auth info in the header, found invalid value in header")
}
found, err := GetAuthInfoHeader(r)
if err != nil {
t.Errorf("got error while getting auth info: %s", err)
}
if found.Realm != info.Realm {
t.Errorf("expected realm to be %s, but got %s", info.Realm, found.Realm)
}
if found.UserName != info.UserName {
t.Errorf("expected UserName to be %s, but got %s", info.UserName, found.UserName)
}
}