diff --git a/test-app/spec/integration/auth_tests_spec.rb b/test-app/spec/integration/auth_tests_spec.rb index 876e001..21917fb 100644 --- a/test-app/spec/integration/auth_tests_spec.rb +++ b/test-app/spec/integration/auth_tests_spec.rb @@ -1,61 +1,61 @@ -# # frozen_string_literal: true -# -# require 'swagger_helper' -# -# describe 'Auth Tests API', type: :request, swagger_doc: 'v1/swagger.json' do -# path '/auth-tests/basic' do -# post 'Authenticates with basic auth' do -# tags 'Auth Tests' -# operationId 'testBasicAuth' -# security [basic_auth: []] -# -# response '204', 'Valid credentials' do -# let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } -# run_test! -# end -# -# response '401', 'Invalid credentials' do -# let(:Authorization) { "Basic #{::Base64.strict_encode64('foo:bar')}" } -# run_test! -# end -# end -# end -# -# path '/auth-tests/api-key' do -# post 'Authenticates with an api key' do -# tags 'Auth Tests' -# operationId 'testApiKey' -# security [api_key: []] -# -# response '204', 'Valid credentials' do -# let(:api_key) { 'foobar' } -# run_test! -# end -# -# response '401', 'Invalid credentials' do -# let(:api_key) { 'barfoo' } -# run_test! -# end -# end -# end -# -# path '/auth-tests/basic-and-api-key' do -# post 'Authenticates with basic auth and api key' do -# tags 'Auth Tests' -# operationId 'testBasicAndApiKey' -# security [{ basic_auth: [], api_key: [] }] -# -# response '204', 'Valid credentials' do -# let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } -# let(:api_key) { 'foobar' } -# run_test! -# end -# -# response '401', 'Invalid credentials' do -# let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } -# let(:api_key) { 'barfoo' } -# run_test! -# end -# end -# end -# end +# frozen_string_literal: true + +require 'swagger_helper' + +describe 'Auth Tests API', type: :request, swagger_doc: 'v1/swagger.json' do + path '/auth-tests/basic' do + post 'Authenticates with basic auth' do + tags 'Auth Tests' + operationId 'testBasicAuth' + security [basic_auth: []] + + response '204', 'Valid credentials' do + let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } + run_test! + end + + response '401', 'Invalid credentials' do + let(:Authorization) { "Basic #{::Base64.strict_encode64('foo:bar')}" } + run_test! + end + end + end + + path '/auth-tests/api-key' do + post 'Authenticates with an api key' do + tags 'Auth Tests' + operationId 'testApiKey' + security [api_key: []] + + response '204', 'Valid credentials' do + let(:api_key) { 'foobar' } + run_test! + end + + response '401', 'Invalid credentials' do + let(:api_key) { 'barfoo' } + run_test! + end + end + end + + path '/auth-tests/basic-and-api-key' do + post 'Authenticates with basic auth and api key' do + tags 'Auth Tests' + operationId 'testBasicAndApiKey' + security [{ basic_auth: [], api_key: [] }] + + response '204', 'Valid credentials' do + let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } + let(:api_key) { 'foobar' } + run_test! + end + + response '401', 'Invalid credentials' do + let(:Authorization) { "Basic #{::Base64.strict_encode64('jsmith:jspass')}" } + let(:api_key) { 'barfoo' } + run_test! + end + end + end +end diff --git a/test-app/swagger/v1/swagger.json b/test-app/swagger/v1/swagger.json index 9660b82..6375b5f 100644 --- a/test-app/swagger/v1/swagger.json +++ b/test-app/swagger/v1/swagger.json @@ -5,6 +5,81 @@ "version": "v1" }, "paths": { + "/auth-tests/basic": { + "post": { + "summary": "Authenticates with basic auth", + "tags": [ + "Auth Tests" + ], + "operationId": "testBasicAuth", + "security": [ + { + "basic_auth": [ + + ] + } + ], + "responses": { + "204": { + "description": "Valid credentials" + }, + "401": { + "description": "Invalid credentials" + } + } + } + }, + "/auth-tests/api-key": { + "post": { + "summary": "Authenticates with an api key", + "tags": [ + "Auth Tests" + ], + "operationId": "testApiKey", + "security": [ + { + "api_key": [ + + ] + } + ], + "responses": { + "204": { + "description": "Valid credentials" + }, + "401": { + "description": "Invalid credentials" + } + } + } + }, + "/auth-tests/basic-and-api-key": { + "post": { + "summary": "Authenticates with basic auth and api key", + "tags": [ + "Auth Tests" + ], + "operationId": "testBasicAndApiKey", + "security": [ + { + "basic_auth": [ + + ], + "api_key": [ + + ] + } + ], + "responses": { + "204": { + "description": "Valid credentials" + }, + "401": { + "description": "Invalid credentials" + } + } + } + }, "/blogs": { "post": { "summary": "Creates a blog",