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

fix(3123): Restrict overwriting username on create Event #3129

Merged
merged 1 commit into from
Jun 3, 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
3 changes: 3 additions & 0 deletions plugins/events/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ module.exports = () => ({

if (creator) {
payload.creator = creator;
if (creator.username !== 'sd:scheduler') {
payload.creator.username = username;
}
} else if (scope.includes('pipeline')) {
payload.creator = {
name: 'Pipeline Access Token', // Display name
Expand Down
37 changes: 34 additions & 3 deletions test/plugins/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,19 +416,50 @@ describe('event plugin test', () => {
});
});

it('returns 201 when it successfully creates an event with causeMessage and creator passed in', () => {
it('returns 201 when it successfully creates an event with causeMessage and scheduler creator passed in', () => {
delete options.payload.parentBuildId;
delete eventConfig.parentBuildId;
eventConfig.causeMessage = 'Started by periodic build scheduler';
eventConfig.creator = { name: 'Screwdriver scheduler', username: 'scheduler' };
eventConfig.creator = { name: 'Screwdriver scheduler', username: 'sd:scheduler' };
eventConfig.meta = {};
options.payload = {
pipelineId,
startFrom: '~commit',
causeMessage: 'Started by periodic build scheduler',
creator: {
name: 'Screwdriver scheduler',
username: 'scheduler'
username: 'sd:scheduler'
}
};

return server.inject(options).then(reply => {
expectedLocation = {
host: reply.request.headers.host,
port: reply.request.headers.port,
protocol: reply.request.server.info.protocol,
pathname: `${options.url}/12345`
};
assert.equal(reply.statusCode, 201);
assert.calledWith(eventFactoryMock.create, eventConfig);
assert.strictEqual(reply.headers.location, urlLib.format(expectedLocation));
assert.calledWith(eventFactoryMock.scm.getCommitSha, scmConfig);
assert.notCalled(eventFactoryMock.scm.getPrInfo);
});
});

it('returns 201 when it successfully creates an event with creator passed in not overwrite username', () => {
delete options.payload.parentBuildId;
delete eventConfig.parentBuildId;
eventConfig.causeMessage = 'Manually Started by foobar';
eventConfig.creator = { name: 'foo bar', username: 'myself' };
eventConfig.meta = {};
options.payload = {
pipelineId,
startFrom: '~commit',
causeMessage: 'Manually Started by foobar',
creator: {
name: 'foo bar',
username: 'foobar'
}
};

Expand Down