chore(auth): Add documentation and specs

This commit is contained in:
Austin Kabiru 2018-11-30 14:23:11 +03:00
parent b0712418a3
commit 875bbfa04b
No known key found for this signature in database
GPG Key ID: 6D6C5615C3E00288
3 changed files with 79 additions and 2 deletions

View File

@ -44,9 +44,9 @@ Once you have an API that can describe itself in Swagger, you've opened the trea
```ruby
rails g rswag:install
```
Or run the install generators for each package separately if you installed Rswag as separate gems, as indicated above:
```ruby
rails g rswag:api:install rswag:ui:install
RAILS_ENV=test rails g rswag:specs:install
@ -477,6 +477,17 @@ Rswag::Ui.configure do |c|
end
```
### Enable Simple Basic Auth for swagger-ui
You can also update the _rswag-ui.rb_ initializer, installed with rswag-ui to specify a username and password should you want to keep your documentation private.
```ruby
Rswag::Ui.configure do |c|
c.basic_auth_enabled = true
c.basic_auth_credentials 'username', 'password'
end
```
### Route Prefix for the swagger-ui ###
Similar to rswag-api, you can customize the swagger-ui path by changing it's mount prefix in _routes.rb_:

View File

@ -0,0 +1,50 @@
require 'spec_helper'
RSpec.describe Rswag::Ui::Configuration do
describe '#swagger_endpoints'
describe '#basic_auth_enabled' do
context 'when unspecified' do
it 'defaults to false' do
configuration = described_class.new
basic_auth_enabled = configuration.basic_auth_enabled
expect(basic_auth_enabled).to be(false)
end
end
context 'when specified' do
context 'when set to true' do
it 'returns true' do
configuration = described_class.new
configuration.basic_auth_enabled = true
basic_auth_enabled = configuration.basic_auth_enabled
expect(basic_auth_enabled).to be(true)
end
end
context 'when set to false' do
it 'returns false' do
configuration = described_class.new
configuration.basic_auth_enabled = false
basic_auth_enabled = configuration.basic_auth_enabled
expect(basic_auth_enabled).to be(false)
end
end
end
end
describe '#basic_auth_credentials' do
it 'sets the username and password' do
configuration = described_class.new
configuration.basic_auth_credentials 'foo', 'bar'
credentials = configuration.config_object[:basic_aut]
expect(credentials).to eq(username: 'foo', password: 'bar')
end
end
describe '#get_binding'
end

View File

@ -0,0 +1,16 @@
require 'bundler/setup'
require 'rack'
require 'rswag/ui/configuration'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
config.expect_with :rspec do |c|
c.syntax = :expect
end
end