Skip to content
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

🔥 [NTFY] - Fix basic/bearer authentication #483

Merged
merged 1 commit into from
Nov 12, 2024
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
19 changes: 15 additions & 4 deletions app/triggers/providers/ntfy/Ntfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ class Ntfy extends Trigger {
* @returns {*}
*/
maskConfiguration() {
return this.configuration;
return {
...this.configuration,
auth: this.configuration.auth ? {
user: Ntfy.mask(this.configuration.user),
password: Ntfy.mask(this.configuration.password),
token: Ntfy.mask(this.configuration.token),
} : undefined,
};
}

/**
Expand Down Expand Up @@ -75,15 +82,19 @@ class Ntfy extends Trigger {
body,
json: true,
};
if (this.configuration.auth && this.configuration.user && this.configuration.password) {
if (
this.configuration.auth
&& this.configuration.auth.user
&& this.configuration.auth.password
) {
options.auth = {
user: this.configuration.auth.user,
pass: this.configuration.auth.password,
};
}
if (this.configuration.auth && this.configuration.token) {
if (this.configuration.auth && this.configuration.auth.token) {
options.auth = {
bearer: this.configuration.auth.bearer,
bearer: this.configuration.auth.token,
};
}
return rp(options);
Expand Down
82 changes: 81 additions & 1 deletion app/triggers/providers/ntfy/Ntfy.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { ValidationError } = require('joi');

const rp = require('request-promise-native');
const Ntfy = require('./Ntfy');

jest.mock('request-promise-native');

const ntfy = new Ntfy();

const configurationValid = {
Expand All @@ -19,6 +21,10 @@ const configurationValid = {
batchtitle: '${count} updates available',
};

beforeEach(() => {
jest.resetAllMocks();
});

test('validateConfiguration should return validated configuration when valid', () => {
const validatedConfiguration = ntfy.validateConfiguration(configurationValid);
expect(validatedConfiguration).toStrictEqual(configurationValid);
Expand All @@ -32,3 +38,77 @@ test('validateConfiguration should throw error when invalid', () => {
ntfy.validateConfiguration(configuration);
}).toThrowError(ValidationError);
});

test('trigger should call http client', async () => {
ntfy.configuration = configurationValid;
const container = {
name: 'container1',
};
await ntfy.trigger(container);
expect(rp).toHaveBeenCalledWith({
body: {
message: 'Container container1 running with can be updated to \n',
priority: 2,
title: 'New found for container container1',
topic: 'xxx',
},
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
json: true,
uri: 'http://xxx.com',
});
});

test('trigger should use basic auth when configured like that', async () => {
ntfy.configuration = {
...configurationValid,
auth: { user: 'user', password: 'pass' },
};
const container = {
name: 'container1',
};
await ntfy.trigger(container);
expect(rp).toHaveBeenCalledWith({
body: {
message: 'Container container1 running with can be updated to \n',
priority: 2,
title: 'New found for container container1',
topic: 'xxx',
},
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
json: true,
uri: 'http://xxx.com',
auth: { user: 'user', pass: 'pass' },
});
});

test('trigger should use bearer auth when configured like that', async () => {
ntfy.configuration = {
...configurationValid,
auth: { token: 'token' },
};
const container = {
name: 'container1',
};
await ntfy.trigger(container);
expect(rp).toHaveBeenCalledWith({
body: {
message: 'Container container1 running with can be updated to \n',
priority: 2,
title: 'New found for container container1',
topic: 'xxx',
},
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
json: true,
uri: 'http://xxx.com',
auth: { bearer: 'token' },
});
});
3 changes: 3 additions & 0 deletions docs/changelog/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

# 7.1.1 (wip)
- :fire: [NTFY] - Fix basic/bearer authentication

# 7.1.0
- :star: [GOTIFY] - Add support for [Gotify](/configuration/triggers/gotify/) trigger
- :star: [NTFY] - Add support for [Ntfy](/configuration/triggers/ntfy/) trigger
Expand Down
2 changes: 1 addition & 1 deletion e2e/features/api-container.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Feature: WUD Container API Exposure
And response body path $.image.tag.semver should be false
And response body path $.image.digest.value should be sha256:f94d6dd9b5761f33a21bb92848a1f70ea11a1c15f3a142c19a44ea3a4c545a4d
And response body path $.result.tag should be latest
And response body path $.result.digest should be sha256:367678a80c0be120f67f3adfccc2f408bd2c1319ed98c1975ac88e750d0efe26
And response body path $.result.digest should be sha256:5341b734e75ce46bbb8e02476434217fd771e23df9a4bfea756a6f3a4a521d3e
And response body path $.updateAvailable should be true

Scenario: WUD must allow to get a container with its link
Expand Down