Skip to content

Conversation

@alex-ac
Copy link

@alex-ac alex-ac commented Dec 2, 2025

What does it do ?

Current implementation does not handle special characters in pihole password correctly. It skips proper JSON marshalling of the request & sends invalid json to pihole API. This change fixes it by introducing proper JSON marshalling.

Motivation

I've hit this problem myself on my homelab setup, here's a log:

time="2025-12-02T13:20:36Z" level=debug msg="Fetching new token from http://http.pi-hole.svc.cluster.local/api/auth"
time="2025-12-02T13:20:36Z" level=debug msg="Error on request http://http.pi-hole.svc.cluster.local/api/auth"
time="2025-12-02T13:20:36Z" level=debug msg="Body of the request {}"
time="2025-12-02T13:20:36Z" level=fatal msg="received 400 status code from request: [bad_request] Invalid request body data (no valid JSON), error at hint (\\hei0MachahmaeThoo7u\"}) - 0.000226s"

Hint in the log is part of the request json starting with invalid escape sequence \h which happened because my password contains backslash.

More

  • Yes, this PR title follows Conventional Commits
  • Yes, I added unit tests
  • Yes, I updated end user documentation accordingly

Updated test of pihole provider to create a pihole api client with
password containing special characters.

When requesting API token, current implementation does not perform
proper json marshalling of request. That results in sending invalid
json & getting 400 bad request error if password contains special
characters which break json syntax.

Run of the test with current code:

    === RUN   TestNewPiholeClientV6
        clientV6_test.go:129: invalid character 'w' in string escape code
            clientV6_test.go:200: Post "http://127.0.0.1:57465/api/auth": EOF
            --- FAIL: TestNewPiholeClientV6 (0.01s)
Added proper JSON marshalling of API token request body.
That fixes support of special characters in pihole password.

The previously updated test now passes:

    === RUN   TestNewPiholeClientV6
    --- PASS: TestNewPiholeClientV6 (0.00s)
@k8s-ci-robot k8s-ci-robot added the provider Issues or PRs related to a provider label Dec 2, 2025
@k8s-ci-robot k8s-ci-robot requested a review from vflaux December 2, 2025 13:58
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign raffo for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 2, 2025

CLA Signed
The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @alex-ac!

It looks like this is your first PR to kubernetes-sigs/external-dns 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/external-dns has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 2, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @alex-ac. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Dec 2, 2025
@alex-ac alex-ac changed the title fix: Support special characters in pihole password fix(pihole): Support special characters in pihole password Dec 2, 2025
@mloiseleur
Copy link
Collaborator

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 3, 2025
@mloiseleur mloiseleur changed the title fix(pihole): Support special characters in pihole password fix(pihole): support special characters in pihole password Dec 3, 2025
@coveralls
Copy link

Pull Request Test Coverage Report for Build 19861145459

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 20 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.008%) to 78.676%

Files with Coverage Reduction New Missed Lines %
openshift_route.go 1 79.49%
pihole/clientV6.go 19 92.26%
Totals Coverage Status
Change from base Build 19855624490: -0.008%
Covered Lines: 16013
Relevant Lines: 20353

💛 - Coveralls

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\"²` {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. provider Issues or PRs related to a provider size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants