Provide valid configuration for auth

This commit removes a additional authenticate method that is defined in the token_spec tests. Instead, authenticate is used from api/helpers. To support this change the config provided is updated to specify a dummy provider. Without this change authenticate cannot be tested along with token_spec because token_spec redefines authenticate.
This commit is contained in:
kirby@puppetlabs.com 2018-06-27 14:41:27 -07:00
parent 9fa27af8e5
commit cbd4567454

View file

@ -1,16 +1,6 @@
require 'spec_helper' require 'spec_helper'
require 'rack/test' require 'rack/test'
module Vmpooler
class API
module Helpers
def authenticate(auth, username_str, password_str)
username_str == 'admin' and password_str == 's3cr3t'
end
end
end
end
describe Vmpooler::API::V1 do describe Vmpooler::API::V1 do
include Rack::Test::Methods include Rack::Test::Methods
@ -39,7 +29,15 @@ describe Vmpooler::API::V1 do
end end
context '(auth configured)' do context '(auth configured)' do
let(:config) { { auth: true } } let(:config) {
{
auth: {
'provider' => 'dummy'
}
}
}
let(:username_str) { 'admin' }
let(:password_str) { 's3cr3t' }
it 'returns a 401 if not authed' do it 'returns a 401 if not authed' do
get "#{prefix}/token" get "#{prefix}/token"
@ -69,7 +67,13 @@ describe Vmpooler::API::V1 do
end end
context '(auth configured)' do context '(auth configured)' do
let(:config) { { auth: true } } let(:config) {
{
auth: {
'provider' => 'dummy'
}
}
}
it 'returns a 401 if not authed' do it 'returns a 401 if not authed' do
post "#{prefix}/token" post "#{prefix}/token"
@ -146,7 +150,13 @@ describe Vmpooler::API::V1 do
end end
context '(auth configured)' do context '(auth configured)' do
let(:config) { { auth: true } } let(:config) {
{
auth: {
'provider' => 'dummy'
}
}
}
it 'returns a 401 if not authed' do it 'returns a 401 if not authed' do
delete "#{prefix}/token/this" delete "#{prefix}/token/this"