Skip to content

Dashboard backend: set current user in job.post #674

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

Merged
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
5 changes: 4 additions & 1 deletion src/dashboard/server/api/controllers/cluster/jobs.post.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ const uuid = require('uuid')
/**
* @typedef {Object} State
* @property {import('../../services/cluster')} cluster
* @property {import('../../services/user')} user
*/

/** @type {import('koa').Middleware<State>} */
module.exports = async context => {
const { cluster } = context.state
const { cluster, user } = context.state

const job = Object.assign({}, context.request.body)

job['userName'] = user.email
job['familyToken'] = uuid()
job['isParent'] = 1

Expand Down
15 changes: 15 additions & 0 deletions src/dashboard/server/test/controllers/cluster/jobs.post.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const axiosist = require('axiosist')
const sinon = require('sinon')
const nock = require('nock')
const _ = require('lodash')

const User = require('../../../api/services/user')
const api = require('../../../api').callback()

Expand Down Expand Up @@ -45,4 +47,17 @@ describe('POST /clusters/:clusterid/jobs', () => {
{}, {params: userParams})
response.status.should.equal(400)
})

it('should forcely set userName as current user in the submitted job', async () => {
nock('http://universe')
.post('/PostJob', _.matches({ userName: '[email protected]' }))
.reply(200, {
message: 'job adding succeeded'
})
sinon.stub(User.prototype, 'fillIdFromWinbind').resolves()

const response = await axiosist(api).post('/clusters/Universe/jobs',
{ vcName: 'test', userName: 'foo' }, { params: userParams })
response.status.should.equal(200)
})
})