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

Add Heroku log drain host format check #203

Merged
merged 3 commits into from
Sep 1, 2022
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
9 changes: 7 additions & 2 deletions src/checks/herokuLogDrain.check.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ class HerokuLogDrainCheck extends Check {
severity = defaultSeverity,
herokuAuthToken = process.env.HEROKU_AUTH_TOKEN,
herokuAppId = process.env.HEROKU_APP_ID,
herokuAppName = process.env.HEROKU_APP_NAME,
...options
}) {
super({ panicGuide, technicalSummary, businessImpact, severity, ...options });
this.herokuAuthToken = herokuAuthToken;
this.herokuAppId = herokuAppId;
this.herokuAppName = herokuAppName;
}

validateHerokuConfig() {
Expand Down Expand Up @@ -92,8 +94,11 @@ class HerokuLogDrainCheck extends Check {
throw new Error('log drain sourcetype parameter is present; sourcetype should instead be specified on the HEC (HTTP Event Collector) token');
}

if (!parsedUrl.searchParams.get('host')) {
throw new Error('log drain host parameter is not set');
if (
!parsedUrl.searchParams.get('host') ||
parsedUrl.searchParams.get('host') !== `${this.herokuAppName}.herokuapp.com`
) {
throw new Error('log drain host parameter is not set or is not the app\'s name (excluding protocol and path)');
}

if (!parsedUrl.searchParams.get('channel')) {
Expand Down
35 changes: 28 additions & 7 deletions test/herokuLogDrain.check.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mockValidResponse = {
ok: true,
json: sinon.stub().resolves([
{
url: 'https://x:[email protected]/services/collector/raw?source=mock-system-code&host=mock-host&channel=mock-channel'
url: 'https://x:[email protected]/services/collector/raw?source=mock-system-code&host=mock-valid-app-name.herokuapp.com&channel=mock-channel'
}
])
};
Expand Down Expand Up @@ -44,7 +44,8 @@ describe.only('Heroku Log Drain Check', () => {
id: 'mock-id',
name: 'mock-name',
herokuAuthToken: 'mock-auth-token',
herokuAppId: 'mock-valid-app-id'
herokuAppId: 'mock-valid-app-id',
herokuAppName: 'mock-valid-app-name',
});
});

Expand Down Expand Up @@ -194,7 +195,7 @@ describe.only('Heroku Log Drain Check', () => {
beforeEach(done => {
mockValidResponse.json.resolves([
{
url: 'https://x:[email protected]/services/collector/raw?host=mock-host&channel=mock-channel'
url: 'https://x:[email protected]/services/collector/raw?host=mock-valid-app-name.herokuapp.com&channel=mock-channel'
}
]);
check.start();
Expand All @@ -214,7 +215,7 @@ describe.only('Heroku Log Drain Check', () => {
beforeEach(done => {
mockValidResponse.json.resolves([
{
url: 'https://x:[email protected]/services/collector/raw?source=invalid&host=mock-host&channel=mock-channel'
url: 'https://x:[email protected]/services/collector/raw?source=invalid&host=mock-valid-app-name.herokuapp.com&channel=mock-channel'
}
]);
check.start();
Expand All @@ -234,7 +235,7 @@ describe.only('Heroku Log Drain Check', () => {
beforeEach(done => {
mockValidResponse.json.resolves([
{
url: 'https://x:[email protected]/services/collector/raw?sourcetype=mock-sourcetype&source=mock-system-code&host=mock-host&channel=mock-channel'
url: 'https://x:[email protected]/services/collector/raw?sourcetype=mock-sourcetype&source=mock-system-code&host=mock-valid-app-name.herokuapp.com&channel=mock-channel'
}
]);
check.start();
Expand Down Expand Up @@ -263,7 +264,27 @@ describe.only('Heroku Log Drain Check', () => {

it('it sets the check properties to indicate failure', () => {
const status = check.getStatus();
expect(status.checkOutput).to.equal('Heroku log drains are misconfigured: log drain host parameter is not set');
expect(status.checkOutput).to.equal('Heroku log drains are misconfigured: log drain host parameter is not set or is not the app\'s name (excluding protocol and path)');
expect(status.ok).to.be.false;
});

});

describe('when the app log drain has a host query parameter in the incorrect format', () => {

beforeEach(done => {
mockValidResponse.json.resolves([
{
url: 'https://x:[email protected]/services/collector/raw?source=mock-system-code&host=mock-invalid-app-name.herokuapp.com&channel=mock-channel'
}
]);
check.start();
setTimeout(done);
});

it('it sets the check properties to indicate failure', () => {
const status = check.getStatus();
expect(status.checkOutput).to.equal('Heroku log drains are misconfigured: log drain host parameter is not set or is not the app\'s name (excluding protocol and path)');
expect(status.ok).to.be.false;
});

Expand All @@ -274,7 +295,7 @@ describe.only('Heroku Log Drain Check', () => {
beforeEach(done => {
mockValidResponse.json.resolves([
{
url: 'https://x:[email protected]/services/collector/raw?source=mock-system-code&host=mock-host'
url: 'https://x:[email protected]/services/collector/raw?source=mock-system-code&host=mock-valid-app-name.herokuapp.com'
}
]);
check.start();
Expand Down