mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
ability to return api key from api using login
This commit is contained in:
parent
1274e9fa63
commit
9f8afbd18e
2 changed files with 31 additions and 0 deletions
|
@ -110,6 +110,12 @@ get '/api/info' do
|
|||
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)
|
||||
{
|
||||
info: {
|
||||
|
|
|
@ -197,6 +197,31 @@ describe 'api delete' do
|
|||
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
|
||||
it 'fails with no auth' do
|
||||
post '/api/upload'
|
||||
|
|
Loading…
Add table
Reference in a new issue