gris 0.4.7 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: baf6e7fb8bfc35fe35e8bdd84f973ffd239306c3
4
- data.tar.gz: 655b2b8bdbb97fb442f794c6cb550d235c351a28
3
+ metadata.gz: 469f407d1a43e892def021b0c73092149814d21f
4
+ data.tar.gz: 8b72d138c252746c3014777d833e36e1bfab3182
5
5
  SHA512:
6
- metadata.gz: 60a27cf6ac36461e47a3f8a06f2785e4ad07fc461deaae7791e8eb40751847791a36f8822316de8529946c5ee1cec408ec8374b419c6d4a30d30a7d74e301bff
7
- data.tar.gz: e42765faf069b860feeec35d85c4903b9e681698d75744e9ed7a943cedbe3e6cd92baac8daea41e6e7afa2ac96e3e88e76476e92d1d9a3b4fb97d29f1ba1d917
6
+ metadata.gz: c5a56604d2cef58e60e31b41740e4e61283d5986076d47bbee7d1e2410ee010c34514c1e70876b920a7564e97859fe51273f7239d9edeae826e30add9af2610a
7
+ data.tar.gz: d05838ce67e8f22f9c0e72247a07f0978a5331cd481134016b686fb9c9051a9022a4eed5d00c06c372118439322beb00d31827d7f3c5a7970659c18c3c072624
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.4.7)
4
+ gris (0.4.8)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
6
  chronic (~> 0.10.0)
7
7
  dalli (~> 2.7)
data/lib/gris.rb CHANGED
@@ -14,7 +14,6 @@ require 'hashie-forbidden_attributes'
14
14
  require 'gris/application'
15
15
  require 'gris/caching'
16
16
  require 'gris/deprecations'
17
- require 'gris/grape_extensions/authentication_helpers'
18
17
  require 'gris/grape_extensions/crud_helpers'
19
18
  require 'gris/grape_extensions/date_time_helpers'
20
19
  require 'gris/grape_extensions/error_helpers'
@@ -2,15 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe <%= name.classify.pluralize %>Endpoint do
4
4
  include Rack::Test::Methods
5
- context 'with a running app' do
6
- include_context 'with a running app'
7
-
8
- it_should_behave_like 'an endpoint with token_authentication!', [
9
- ['get', '/<%= name.tableize %>'], ['post', '/<%= name.tableize %>'],
10
- ['get', '/<%= name.tableize %>/1'], ['patch', '/<%= name.tableize %>/2'],
11
- ['delete', '/<%= name.tableize %>/3']
12
- ]
13
- end
14
5
 
15
6
  context 'with a running app and token authorized client' do
16
7
  include_context 'with a running app and token authorized client'
@@ -3,19 +3,6 @@ class ApplicationEndpoint < Grape::API
3
3
  formatter :json, Grape::Formatter::Roar
4
4
  content_type :json, 'application/hal+json'
5
5
 
6
- helpers do
7
- include Gris::AuthenticationHelpers
8
- end
9
-
10
- # Adds a simple environment variable based
11
- # token authentication scheme to your endpoints.
12
- # Alternatively, this token_authentication!
13
- # method can be added to individual endpoints.
14
- #
15
- before do
16
- token_authentication!
17
- end
18
-
19
6
  desc 'Get the Root API Endpoint'
20
7
  get do
21
8
  present self, with: RootPresenter
@@ -2,20 +2,11 @@ shared_context 'with a running app' do
2
2
  let(:app) { Rack::Builder.parse_file('config.ru').first }
3
3
  end
4
4
 
5
- shared_context 'with token authorization' do
6
- let(:permitted_token) { Gris.secrets.permitted_tokens }
7
- before(:each) do
8
- header 'Http-Authorization', permitted_token
9
- end
10
- end
11
-
12
5
  shared_context 'with a running app and token authorized client' do
13
6
  include_context 'with a running app'
14
- include_context 'with token authorization'
15
7
 
16
8
  let(:client) do
17
9
  Hyperclient.new('http://example.org/') do |client|
18
- client.headers['Http-Authorization'] = permitted_token
19
10
  client.connection(default: false) do |conn|
20
11
  conn.request :hal_json
21
12
  conn.response :json
data/lib/gris/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.4.7'
2
+ VERSION = '0.4.8'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -82,8 +82,6 @@ describe Gris::Generators::ApiGenerator do
82
82
  api_code = File.read(expected_api_file)
83
83
  expect(api_code).to match(/describe ArticlesEndpoint/)
84
84
  expect(api_code).to match(/returns an article/)
85
- expect(api_code).to match(/it_should_behave_like 'an endpoint with token_authentication!'/)
86
- expect(api_code).to match %r{'get', '/articles/1'}
87
85
  end
88
86
 
89
87
  it 'creates a fabricator' do
@@ -110,9 +110,5 @@ describe Gris::Generators::ScaffoldGenerator do
110
110
  expect(root_presenter_file).to match(/endpoint_link :health/)
111
111
  end
112
112
  end
113
-
114
- it 'generates a token authentication spec helper endpoint' do
115
- expect(File).to exist("#{app_path}/spec/support/shared_authentication_spec_helper.rb")
116
- end
117
113
  end
118
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
@@ -367,8 +367,6 @@ files:
367
367
  - lib/gris/generators/templates/scaffold/spec/endpoints/cors_spec.rb.tt
368
368
  - lib/gris/generators/templates/scaffold/spec/spec_helper.rb
369
369
  - lib/gris/generators/templates/scaffold/spec/support/app_helper.rb
370
- - lib/gris/generators/templates/scaffold/spec/support/shared_authentication_spec_helper.rb
371
- - lib/gris/grape_extensions/authentication_helpers.rb
372
370
  - lib/gris/grape_extensions/crud_helpers.rb
373
371
  - lib/gris/grape_extensions/date_time_helpers.rb
374
372
  - lib/gris/grape_extensions/error_helpers.rb
@@ -389,19 +387,16 @@ files:
389
387
  - spec/generators/api_generator_spec.rb
390
388
  - spec/generators/migration_generator_spec.rb
391
389
  - spec/generators/scaffold_generator_spec.rb
392
- - spec/grape_extensions/authentication_helpers_spec.rb
393
390
  - spec/grape_extensions/crud_helpers_spec.rb
394
391
  - spec/grape_extensions/date_time_helpers_spec.rb
395
392
  - spec/grape_extensions/error_helpers_spec.rb
396
393
  - spec/identity_spec.rb
397
394
  - spec/integration/application_error_response_spec.rb
398
- - spec/integration/token_authentication_spec.rb
399
395
  - spec/output_formatters/presenter_link_helpers_spec.rb
400
396
  - spec/secrets_spec.rb
401
397
  - spec/spec_helper.rb
402
398
  - spec/support/caching_helper.rb
403
399
  - spec/support/integration_setup.rb
404
- - spec/support/spec_api_auth_helper.rb
405
400
  - spec/support/spec_api_error_helper.rb
406
401
  - spec/support/spec_crud_helper.rb
407
402
  - spec/support/spec_generators_helper.rb
@@ -438,19 +433,16 @@ test_files:
438
433
  - spec/generators/api_generator_spec.rb
439
434
  - spec/generators/migration_generator_spec.rb
440
435
  - spec/generators/scaffold_generator_spec.rb
441
- - spec/grape_extensions/authentication_helpers_spec.rb
442
436
  - spec/grape_extensions/crud_helpers_spec.rb
443
437
  - spec/grape_extensions/date_time_helpers_spec.rb
444
438
  - spec/grape_extensions/error_helpers_spec.rb
445
439
  - spec/identity_spec.rb
446
440
  - spec/integration/application_error_response_spec.rb
447
- - spec/integration/token_authentication_spec.rb
448
441
  - spec/output_formatters/presenter_link_helpers_spec.rb
449
442
  - spec/secrets_spec.rb
450
443
  - spec/spec_helper.rb
451
444
  - spec/support/caching_helper.rb
452
445
  - spec/support/integration_setup.rb
453
- - spec/support/spec_api_auth_helper.rb
454
446
  - spec/support/spec_api_error_helper.rb
455
447
  - spec/support/spec_crud_helper.rb
456
448
  - spec/support/spec_generators_helper.rb
@@ -1,8 +0,0 @@
1
- shared_examples_for 'an endpoint with token_authentication!' do |route_pairs|
2
- route_pairs.each do |route_pair|
3
- it "returns 401 for #{route_pair[0].upcase} #{route_pair[1]}" do
4
- send route_pair[0], route_pair[1]
5
- expect(response_code).to eq 401
6
- end
7
- end
8
- end
@@ -1,21 +0,0 @@
1
- module Gris
2
- module AuthenticationHelpers
3
- def token_authentication!
4
- error!('Forbidden', 401) unless permit_by_headers || permit_by_params
5
- end
6
-
7
- private
8
-
9
- def permit_by_headers
10
- permitted_tokens.include? request.headers['Http-Authorization'] if request.headers['Http-Authorization']
11
- end
12
-
13
- def permit_by_params
14
- permitted_tokens.include? params[:token] if params[:token]
15
- end
16
-
17
- def permitted_tokens
18
- Gris.secrets.permitted_tokens.split(',')
19
- end
20
- end
21
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Gris::AuthenticationHelpers do
4
- include_context 'with secrets from config/secrets.yml'
5
- context 'without permitted token' do
6
- before(:each) do
7
- @helper = SpecApiAuthHelper.new
8
- end
9
-
10
- context '#token_authentication!' do
11
- context 'without matching tokens' do
12
- it 'returns a 401 Forbidden error' do
13
- allow(@helper).to receive(:params).and_return(token: nil)
14
- allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
15
- @helper.token_authentication!
16
- expect(@helper.message).to eq(message: 'Forbidden', status: 401)
17
- end
18
- end
19
- context 'with included params token' do
20
- it 'returns nil' do
21
- allow(@helper).to receive(:params).and_return(token: 'my-token')
22
- allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
23
- expect(@helper.token_authentication!).to be_nil
24
- end
25
- end
26
- context 'with blank params token' do
27
- it 'returns a 401 Forbidden error' do
28
- allow(@helper).to receive(:params).and_return(token: '')
29
- allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => nil)
30
- @helper.token_authentication!
31
- expect(@helper.message).to eq(message: 'Forbidden', status: 401)
32
- end
33
- end
34
- context 'with included request header token' do
35
- it 'returns nil' do
36
- allow(@helper).to receive(:params).and_return(token: nil)
37
- allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => 'my-token')
38
- expect(@helper.token_authentication!).to be_nil
39
- end
40
- end
41
- context 'with blank header token' do
42
- it 'returns a 401 Forbidden error' do
43
- allow(@helper).to receive(:params).and_return(token: nil)
44
- allow(@helper).to receive_message_chain(:request, :headers).and_return('Http-Authorization' => '')
45
- @helper.token_authentication!
46
- expect(@helper.message).to eq(message: 'Forbidden', status: 401)
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
- require 'hyperclient'
3
-
4
- describe 'token authentication' do
5
- include_context 'with a generated app'
6
-
7
- let(:client_url) { "http://localhost:#{app_port}" }
8
- let(:client) { Hyperclient.new(client_url) }
9
-
10
- it 'returns a forbidden error' do
11
- request = Faraday.get client_url
12
- response = JSON.parse request.body
13
- expect(response['error']).to include 'Forbidden'
14
- end
15
-
16
- context 'with correct token query params' do
17
- it 'returns the root presenter' do
18
- client.params['token'] = 'replace-me'
19
- expect(client._links.self._url).to eq client_url
20
- end
21
- end
22
-
23
- context 'with correct Http-Authorization headers' do
24
- it 'returns the root presenter' do
25
- client.headers['Http-Authorization'] = 'replace-me'
26
- expect(client._links.self._url).to eq client_url
27
- end
28
- end
29
- end
@@ -1,15 +0,0 @@
1
- class SpecApiAuthHelper
2
- include Gris::AuthenticationHelpers
3
- include Gris::ErrorHelpers
4
-
5
- attr_accessor :params
6
- attr_accessor :request
7
-
8
- attr_accessor :message
9
- attr_accessor :thrown
10
-
11
- def throw(thrown, message)
12
- @message = message
13
- @thrown = thrown
14
- end
15
- end