mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
Remove mockist tests from main suite.
This commit is contained in:
parent
82f3cccd65
commit
95d4a0b401
1 changed files with 0 additions and 160 deletions
|
|
@ -18,166 +18,6 @@ describe Vmpooler::API::V1 do
|
|||
Vmpooler::API
|
||||
end
|
||||
|
||||
describe '/token' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
end
|
||||
|
||||
describe 'GET /token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { { auth: false } }
|
||||
|
||||
it 'returns a 404' do
|
||||
get "#{prefix}/token"
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) { { auth: true } }
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
get "#{prefix}/token"
|
||||
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'returns a list of tokens if authed' do
|
||||
expect(redis).to receive(:keys).with('vmpooler__token__*').and_return(["vmpooler__token__abc"])
|
||||
expect(redis).to receive(:hgetall).with('vmpooler__token__abc').and_return({"user" => "admin", "created" => "now"})
|
||||
|
||||
authorize 'admin', 's3cr3t'
|
||||
|
||||
get "#{prefix}/token"
|
||||
|
||||
expect(JSON.parse(last_response.body)['abc']['created']).to eq('now')
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { { auth: false } }
|
||||
|
||||
it 'returns a 404' do
|
||||
post "#{prefix}/token"
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before do
|
||||
allow(redis).to receive(:hset).and_return '1'
|
||||
end
|
||||
|
||||
let(:config) { { auth: true } }
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
post "#{prefix}/token"
|
||||
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'returns a token if authed' do
|
||||
authorize 'admin', 's3cr3t'
|
||||
|
||||
post "#{prefix}/token"
|
||||
|
||||
expect(JSON.parse(last_response.body)['token'].length).to be(32)
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '/token/:token' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
end
|
||||
|
||||
describe 'GET /token/:token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { { auth: false } }
|
||||
|
||||
it 'returns a 404' do
|
||||
get "#{prefix}/token/this"
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
let(:config) { {
|
||||
auth: true,
|
||||
pools: [
|
||||
{'name' => 'pool1', 'size' => 5}
|
||||
]
|
||||
} }
|
||||
|
||||
it 'returns a token' do
|
||||
expect(redis).to receive(:hgetall).with('vmpooler__token__this').and_return({'user' => 'admin'})
|
||||
expect(redis).to receive(:smembers).with('vmpooler__running__pool1').and_return(['vmhostname'])
|
||||
expect(redis).to receive(:hget).with('vmpooler__vm__vmhostname', 'token:token').and_return('this')
|
||||
|
||||
get "#{prefix}/token/this"
|
||||
|
||||
expect(JSON.parse(last_response.body)['ok']).to eq(true)
|
||||
expect(JSON.parse(last_response.body)['this']['user']).to eq('admin')
|
||||
expect(JSON.parse(last_response.body)['this']['vms']['running']).to include('vmhostname')
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /token/:token' do
|
||||
context '(auth not configured)' do
|
||||
let(:config) { { auth: false } }
|
||||
|
||||
it 'returns a 404' do
|
||||
delete "#{prefix}/token/this"
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
end
|
||||
|
||||
context '(auth configured)' do
|
||||
before do
|
||||
allow(redis).to receive(:del).and_return '1'
|
||||
end
|
||||
|
||||
let(:config) { { auth: true } }
|
||||
|
||||
it 'returns a 401 if not authed' do
|
||||
delete "#{prefix}/token/this"
|
||||
|
||||
expect_json(ok = false, http = 401)
|
||||
end
|
||||
|
||||
it 'deletes a token if authed' do
|
||||
authorize 'admin', 's3cr3t'
|
||||
|
||||
delete "#{prefix}/token/this"
|
||||
|
||||
expect_json(ok = true, http = 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '/vm' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue