Spec tests for GET /token

This commit is contained in:
Scott Schneider 2015-08-18 19:05:47 -07:00
parent 47deddcc46
commit e4f2777889

View file

@ -27,6 +27,41 @@ describe Vmpooler::API::V1 do
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", "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
context '(auth not configured)' do
let(:config) { { auth: false } }