Skip to content

[Notifier] Fixed authorization problems #58088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Conversation

jirikmik
Copy link

@jirikmik jirikmik commented Aug 26, 2024

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #58085
License MIT

Fixed creating authorization header for username and password auth and added DSN example for token auth to README.

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot

This comment was marked as resolved.

@jirikmik jirikmik changed the base branch from 7.2 to 7.1 August 26, 2024 07:18
@xabbuh xabbuh changed the base branch from 7.1 to 7.2 August 26, 2024 07:34
@carsonbot carsonbot changed the title Fixed authorization problems [Notifier] Fixed authorization problems Aug 26, 2024
@xabbuh xabbuh removed this from the 7.2 milestone Aug 26, 2024
@xabbuh xabbuh added this to the 6.4 milestone Aug 26, 2024
@@ -87,7 +87,7 @@ protected function doSend(MessageInterface $message): SentMessage
$headers = [];

if (null !== $this->user && null !== $this->password) {
$headers['Authorization'] = 'Basic '.rtrim(base64_encode($this->user.':'.$this->password), '=');
$headers['Authorization'] = 'Basic '.base64_encode($this->user.':'.$this->password);
Copy link
Member

Choose a reason for hiding this comment

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

@mikaelkael Would be great if you could have a look here as you contributed the initial code in #50131.

Copy link
Contributor

Choose a reason for hiding this comment

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

@xabbuh: as explain here https://docs.ntfy.sh/publish/#username-password, you don't have final sign equal and this modification breaks associated test https://github.com/symfony/symfony/actions/runs/10555314977/job/29238683518#step:8:1929. As all tests use mocks without direct access to a ntfy server, perhaps your modification is possible but you need to also change tests to be compliant

Copy link
Author

Choose a reason for hiding this comment

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

@xabbuh: as explain here https://docs.ntfy.sh/publish/#username-password, you don't have final sign equal and this modification breaks associated test https://github.com/symfony/symfony/actions/runs/10555314977/job/29238683518#step:8:1929. As all tests use mocks without direct access to a ntfy server, perhaps your modification is possible but you need to also change tests to be compliant

Suggested page not explain you don't have final equal sign. But in case you encode testuser:fakepassword string from Ntfy docs base64 output is without equal sign(s).

Doing tests is totally out of my scope. I just only wanted report bug I have found. Somebody asks me for PR, I did ... sorry :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

The fix looks correct to me, as Base64 encoded strings do not always end with an = character. The = character is used as padding to ensure that the length of the encoded string is a multiple of 4 characters, which is required by the Base64 encoding standard.

So yes, the tests should be adjusted

https://3v4l.org/BHa9R

Copy link
Contributor

@mikaelkael mikaelkael Aug 26, 2024

Choose a reason for hiding this comment

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

@jirikmik: you have the mention of no equal sign in https://docs.ntfy.sh/publish/#query-param, specifically for query param and as @OskarStark said, the case of the doc 'testuser:fakepassword' doesn't need padding. I will try to reproduce #58085 with a real server (not mocked)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah it is:
image

Copy link
Author

Choose a reason for hiding this comment

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

I think screenshot from Ntfy.sh docs is related to "query param" auth, not Basic auth ...

Copy link
Contributor

Choose a reason for hiding this comment

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

In none of the example in the doc, we can find padding equal (for any langage, not only PHP) but it's not a valid reason. During my dev, it didn't made problem. There is perhaps a change with recent version of ntfy. The only way is to have a reproductible test case. As I know in symfony, we didn't depend on external service in test. So I will try to write a failing test case in my https://github.com/mikaelkael/ntfy-notifier (the repository on which I work before integration in symfony).

Copy link
Member

Choose a reason for hiding this comment

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

If I read the linked documentation correctly, stripping the trailing = characters is documented for authenticating via the query parameter,but not for basic auth. This means the proposed change is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was able to reproduce the bug mikaelkael/ntfy-notifier@a9e19dd, I confirm that the correction is good and the only thing to change in test is: mikaelkael/ntfy-notifier@a9e19dd#diff-cfb9cdd160d285443c2bf73a6307b616ce74d3431a19d887ad290425606d2471L114

@@ -5,16 +5,24 @@ Provides [Ntfy](https://docs.ntfy.sh/) integration for Symfony Notifier.

DSN example
-----------

Copy link
Member

Choose a reason for hiding this comment

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

let's keep this blank line

```
where:
- `URL` is the ntfy server which you are using
- if `default` is provided, this will default to the public ntfy server hosted on [ntfy.sh](https://ntfy.sh/).
Copy link
Member

Choose a reason for hiding this comment

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

Looking at README in other bridges, the example DSN uses @default directly. I think it'd be better to follow their lead as using something non-default is going to be the exception.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, I understand. But text is talking about URL which is not in example DSN. With self-hosted Ntfy is default unclear

@@ -73,29 +73,26 @@ protected function doSend(MessageInterface $message): SentMessage
$opts = NtfyOptions::fromNotification($notification);
}

$options = $opts ? $opts->toArray() : [];
$json_options = $opts? $opts->toArray() : [];
Copy link
Member

@fabpot fabpot Aug 27, 2024

Choose a reason for hiding this comment

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

Suggested change
$json_options = $opts? $opts->toArray() : [];
$jsonOptions = $opts ? $opts->toArray() : [];

}

$headers = [];
$client_options = ['json' => $json_options];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$client_options = ['json' => $json_options];
$clientOptions = ['json' => $json_options];

@OskarStark
Copy link
Contributor

Any plans to finish this PR @jirikmik ?

```
NTFY_DSN=ntfy://[USER:PASSWORD]@default[:PORT]/TOPIC?[secureHttp=[on]]
NTFY_DSN=ntfy://URL[:PORT]/TOPIC?[secureHttp=[on]]
```
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a whiteline after and before each code delimiter line?

@fabpot
Copy link
Member

fabpot commented Jan 5, 2025

Closing as there are no more activities. Feel free to reopen when you have time or if someone wants to take over.

@fabpot fabpot closed this Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ntfy Notifier - authorization
8 participants