rack-prx_auth 0.0.2 → 0.0.4

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: 335167c8922061c767796b85563f9f7b5378a6e9
4
- data.tar.gz: 523fd6da97985c6e2e9f78aa20a51d570411dc37
3
+ metadata.gz: e7cde70cde8a0092e5b9b103dca645ead406af8b
4
+ data.tar.gz: 36a0c5162508458ec15e9db7572d1cc1244113fd
5
5
  SHA512:
6
- metadata.gz: f28ac978ac7e87da00f7495da26ff391a2794aecb5c8915052516b414964f800fc6779fe5c087ffce9ecc7612f58ab1caf6f1007a7a4a139a23cc80abbdcafcd
7
- data.tar.gz: a3a3055cfc30a9ececdf51bcb8dd91e2c468e0f10902bd242150dda3a8560878d89fd4f981f256a8b8f882086a26ca102f4d44b23720ca3d2320fccae66ee596
6
+ metadata.gz: 805280d7e1fda15de81c390a9c73d89613cc42843452eeff25481abfec36b6882bc8e8fa58312aba0660d7cf8abecea377127fb8912a359ae74214adc5131b7d
7
+ data.tar.gz: 5b518e3aecb8e4c9c557c1fb7369a092e0b48f902b6e87a5e56fbd407c68e048ea627dc54572a3700d66cdc636f06b21f20451671f88e5fd1cea3604f7cc4619
data/lib/rack/prx_auth.rb CHANGED
@@ -8,9 +8,9 @@ module Rack
8
8
  class PrxAuth
9
9
  attr_reader :public_key
10
10
 
11
- def initialize(app)
11
+ def initialize(app, options = {})
12
12
  @app = app
13
- @public_key = PublicKey.new
13
+ @public_key = PublicKey.new(options[:cert_location])
14
14
  end
15
15
 
16
16
  def call(env)
@@ -2,12 +2,12 @@ module Rack
2
2
  class PrxAuth
3
3
  class PublicKey
4
4
  EXPIRES_IN = 43200
5
- AUTH_URI = URI('https://auth.prx.org/api/v1/certs')
6
5
 
7
- attr_reader :certificate
6
+ attr_reader :certificate, :cert_location
8
7
 
9
- def initialize
8
+ def initialize(cert_location = nil)
10
9
  @created_at = Time.now
10
+ @cert_location = URI(cert_location || 'https://auth.prx.org/api/v1/certs')
11
11
  get_key
12
12
  end
13
13
 
@@ -23,7 +23,7 @@ module Rack
23
23
  end
24
24
 
25
25
  def get_certificate
26
- certs = JSON.parse(Net::HTTP.get(AUTH_URI))
26
+ certs = JSON.parse(Net::HTTP.get(@cert_location))
27
27
  cert_string = certs['certificates'].values[0]
28
28
  OpenSSL::X509::Certificate.new(cert_string)
29
29
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class PrxAuth
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'guard', '~> 2.6', '>= 2.6.1'
24
24
  spec.add_development_dependency 'guard-minitest', '~> 2.3', '>= 2.3.2'
25
+ spec.add_development_dependency 'minitest-stub_any_instance'
25
26
 
26
27
  spec.add_dependency 'rack', '~> 1.5', '>= 1.5.2'
27
28
  spec.add_dependency 'json', '~> 1.8', '>= 1.8.1'
@@ -1,6 +1,7 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/spec'
3
3
  require 'minitest/pride'
4
+ require 'minitest/stub_any_instance'
4
5
  require 'rack/prx_auth'
5
6
 
6
7
  describe Rack::PrxAuth do
@@ -105,4 +106,24 @@ describe Rack::PrxAuth do
105
106
  end
106
107
  end
107
108
  end
109
+
110
+ describe 'initialize' do
111
+ it 'takes a certificate location as an option' do
112
+ Rack::PrxAuth::PublicKey.stub_any_instance(:get_key, nil) do
113
+ prxauth = Rack::PrxAuth.new(app, cert_location: 'http://www.prx-auth.org/api/v1/certs')
114
+ key = prxauth.public_key
115
+ key.cert_location.host.must_equal 'www.prx-auth.org'
116
+ key.cert_location.path.must_equal '/api/v1/certs'
117
+ end
118
+ end
119
+
120
+ it 'uses auth.prx.org if no uri is given' do
121
+ Rack::PrxAuth::PublicKey.stub_any_instance(:get_key, nil) do
122
+ prxauth = Rack::PrxAuth.new(app)
123
+ key = prxauth.public_key
124
+ key.cert_location.host.must_equal 'auth.prx.org'
125
+ key.cert_location.path.must_equal '/api/v1/certs'
126
+ end
127
+ end
128
+ end
108
129
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-prx_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eve Asher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: 2.3.2
81
+ - !ruby/object:Gem::Dependency
82
+ name: minitest-stub_any_instance
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: rack
83
97
  requirement: !ruby/object:Gem::Requirement