Skip to content
Open
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
10 changes: 9 additions & 1 deletion provider/pihole/clientV6.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,15 @@ func (p *piholeClientV6) retrieveNewToken(ctx context.Context) error {
log.Debugf("Fetching new token from %s", apiUrl)

// Define the JSON payload
jsonData := []byte(`{"password":"` + p.cfg.Password + `"}`)
body := struct {
Password string `json:"password"`
}{
Password: p.cfg.Password,
}
jsonData, err := json.Marshal(body)
if err != nil {
return err
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiUrl, bytes.NewBuffer(jsonData))
if err != nil {
Expand Down
19 changes: 17 additions & 2 deletions provider/pihole/clientV6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestNewPiholeClientV6(t *testing.T) {

w.Header().Set("Content-Type", "application/json")

if requestData["password"] != "correct" {
if requestData["password"] != "correct" && requestData["password"] != "correct\\with\"special'characters" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also simply change the existing password to include special characters. Something like this:

Suggested change
if requestData["password"] != "correct" && requestData["password"] != "correct\\with\"special'characters" {
if requestData["password"] != `correct\"²` {

// Return unsuccessful authentication response
w.WriteHeader(http.StatusUnauthorized)
_, err = w.Write([]byte(`{
Expand Down Expand Up @@ -185,7 +185,22 @@ func TestNewPiholeClientV6(t *testing.T) {
t.Fatal(err)
}
if cl.(*piholeClientV6).token != "supersecret" {
t.Error("Parsed invalid token from login response:", cl.(*piholeClient).token)
t.Error("Parsed invalid token from login response:", cl.(*piholeClientV6).token)
}

// Test correct password with special characters
cl, err = newPiholeClientV6(
PiholeConfig{
Server: srvr.URL,
APIVersion: "6",
Password: "correct\\with\"special'characters",
},
)
if err != nil {
t.Fatal(err)
}
if cl.(*piholeClientV6).token != "supersecret" {
t.Error("Parsed invalid token from login response:", cl.(*piholeClientV6).token)
}
}

Expand Down
Loading