ability to return api key from api using login

This commit is contained in:
Kyle Drake 2017-05-13 18:31:51 -05:00
parent 1274e9fa63
commit 9f8afbd18e
2 changed files with 31 additions and 0 deletions

View file

@ -110,6 +110,12 @@ get '/api/info' do
end end
end end
get '/api/key' do
require_api_credentials
current_site.generate_api_key! if current_site.api_key.blank?
api_success api_key: current_site.api_key
end
def api_info_for(site) def api_info_for(site)
{ {
info: { info: {

View file

@ -197,6 +197,31 @@ describe 'api delete' do
end end
end end
describe 'api key' do
it 'generates new key with valid login' do
create_site
basic_authorize @user, @pass
get '/api/key'
res[:result].must_equal 'success'
res[:api_key].must_equal @site.reload.api_key
end
it 'returns existing key' do
create_site
@site.generate_api_key!
basic_authorize @user, @pass
get '/api/key'
res[:api_key].must_equal @site.api_key
end
it 'fails for bad login' do
create_site
basic_authorize 'zero', 'cool'
get '/api/key'
res[:error_type].must_equal 'invalid_auth'
end
end
describe 'api upload' do describe 'api upload' do
it 'fails with no auth' do it 'fails with no auth' do
post '/api/upload' post '/api/upload'