mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
add token dummy auth
This commit is contained in:
parent
9a745ae9ab
commit
533fb54745
1 changed files with 49 additions and 7 deletions
|
|
@ -18,13 +18,55 @@ describe Vmpooler::API::Restart do
|
||||||
|
|
||||||
|
|
||||||
describe '/restart' do
|
describe '/restart' do
|
||||||
|
before(:each) do
|
||||||
|
expect(app).to receive(:run!).once
|
||||||
|
app.execute([:api], config, redis, nil, nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe 'GET /restart' do
|
||||||
|
context '(auth not configured)' do
|
||||||
|
let(:config) { {
|
||||||
|
config: {},
|
||||||
|
auth: false
|
||||||
|
} }
|
||||||
|
|
||||||
|
it 'returns a 404' do
|
||||||
|
get "/restart"
|
||||||
|
expect_json(ok = false, http = 404)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
context '(auth configured)' do
|
||||||
|
let(:config) {
|
||||||
|
{
|
||||||
|
config: {},
|
||||||
|
auth: {
|
||||||
|
'provider' => 'dummy'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let(:username_str) { 'admin' }
|
||||||
|
let(:password_str) { 's3cr3t' }
|
||||||
|
|
||||||
|
it 'returns a 401 if no token is provided' do
|
||||||
|
get "/restart"
|
||||||
|
expect_json(ok = false, http = 401)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'restarts if token is provided' do
|
||||||
|
|
||||||
|
authorize 'admin', 's3cr3t'
|
||||||
|
get "/restart"
|
||||||
|
expect_json(ok = true, http = 200)
|
||||||
|
|
||||||
|
expect(JSON.parse(last_response.body).to eq JSON.parse(JSON.dump({ 'ok' => true, 'message' => 'Restarting ...' })))
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns OK' do
|
|
||||||
get "/restart"
|
|
||||||
|
|
||||||
expect(last_response.status).to eq(200)
|
|
||||||
result = JSON.parse(last_response.body)
|
|
||||||
expect(result).to eq({'ok' => true})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue