add token dummy auth

This commit is contained in:
Tanisha Payne 2021-06-04 11:15:53 -04:00
parent 9a745ae9ab
commit 533fb54745

View file

@ -18,13 +18,55 @@ describe Vmpooler::API::Restart do
describe '/restart' do
before(:each) do
expect(app).to receive(:run!).once
app.execute([:api], config, redis, nil, nil)
end
it 'returns OK' do
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 ...' })))
expect(last_response.status).to eq(200)
result = JSON.parse(last_response.body)
expect(result).to eq({'ok' => true})
end
end
end
end
end