mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Spec tests for GET /token
This commit is contained in:
parent
47deddcc46
commit
e4f2777889
1 changed files with 35 additions and 0 deletions
|
|
@ -27,6 +27,41 @@ describe Vmpooler::API::V1 do
|
||||||
app.settings.set :redis, redis
|
app.settings.set :redis, redis
|
||||||
end
|
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", "timestamp" => "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
|
describe 'POST /token' do
|
||||||
context '(auth not configured)' do
|
context '(auth not configured)' do
|
||||||
let(:config) { { auth: false } }
|
let(:config) { { auth: false } }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue