rails-auth 2.0.2 → 2.0.3

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: b92868091d02352a61ab49fd57ff7c661e896d5e
4
- data.tar.gz: 00216460fde31f72a5e27ef4cec18a856a65eba9
3
+ metadata.gz: 64b07b9bd8dd9957bc0762d864c405c3d6c04da5
4
+ data.tar.gz: 4b87e9e0994d8d02b51c16efc1c98e3bad4402a2
5
5
  SHA512:
6
- metadata.gz: 816e1c6b079531407868899e8d38cd60b23052de9b1e690ee1e8fa567d43981f2fa1710541a5ede5e56af05f3004ad87d06dcd61dbd63851d2fc5614886a722d
7
- data.tar.gz: 6529e98a1bae73735564ab86b8502e9f676b6a3729e0b3bd9cab39e27f0ba89cdd528394798a95c2c263345b62a259f600713adf8aed0944d966d215f57ec6a9
6
+ metadata.gz: 3bf4cb730c096d16d98b31223d726a8885e7df1ce4178ba90549c02111dcd944a894378e54ec43a1636f9467400529c84fdd8f819561378a9f2ef60875d19d4a
7
+ data.tar.gz: 7151a42a23717f89a3bc00c6c6e2298148b0b98154ac909ba2969c40c17164380b02c23a1827aef1eee6a0455c7d52c9cb4972e63db7518668a7cf1a9e54ab66
data/CHANGES.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 2.0.3 (2016-07-20)
2
+
3
+ * [#39](https://github.com/square/rails-auth/pull/39)
4
+ Make credentials idempotent.
5
+ ([@tarcieri])
6
+
7
+ * [#38](https://github.com/square/rails-auth/pull/38)
8
+ Monitor callback must respond to :call.
9
+ ([@tarcieri])
10
+
1
11
  ### 2.0.2 (2016-07-19)
2
12
 
3
13
  * [#37](https://github.com/square/rails-auth/pull/37)
@@ -10,7 +10,7 @@ module Rails
10
10
  extend Forwardable
11
11
  include Enumerable
12
12
 
13
- def_delegators :@credentials, :[], :fetch, :empty?, :key?, :each, :to_hash
13
+ def_delegators :@credentials, :fetch, :empty?, :key?, :each, :to_hash
14
14
 
15
15
  def self.from_rack_env(env)
16
16
  new(env.fetch(Rails::Auth::Env::CREDENTIALS_ENV_KEY, {}))
@@ -22,10 +22,15 @@ module Rails
22
22
  end
23
23
 
24
24
  def []=(type, value)
25
+ return if @credentials.key?(type) && @credentials[type] == value
25
26
  raise TypeError, "expected String for type, got #{type.class}" unless type.is_a?(String)
26
27
  raise AlreadyAuthorizedError, "credential '#{type}' has already been set" if @credentials.key?(type)
27
28
  @credentials[type] = value
28
29
  end
30
+
31
+ def [](type)
32
+ @credentials[type.to_s]
33
+ end
29
34
  end
30
35
  end
31
36
  end
@@ -5,7 +5,7 @@ module Rails
5
5
  # or failure. Useful for logging or monitoring systems for AuthZ failures
6
6
  class Middleware
7
7
  def initialize(app, callback)
8
- raise TypeError, "expected Proc callback, got #{callback.class}" unless callback.is_a?(Proc)
8
+ raise ArgumentError, "callback must respond to :call" unless callback.respond_to?(:call)
9
9
 
10
10
  @app = app
11
11
  @callback = callback
@@ -3,6 +3,6 @@
3
3
  module Rails
4
4
  # Pluggable authentication and authorization for Rack/Rails
5
5
  module Auth
6
- VERSION = "2.0.2".freeze
6
+ VERSION = "2.0.3".freeze
7
7
  end
8
8
  end
@@ -21,10 +21,29 @@ RSpec.describe Rails::Auth::Credentials do
21
21
  end
22
22
  end
23
23
 
24
- describe "[]=" do
25
- it "raises AlreadyAuthorizedError if credential has already been set" do
24
+ context "when called twice for the same credential type" do
25
+ let(:example_credential) { double(:credential1) }
26
+ let(:second_credential) { double(:credential2) }
27
+
28
+ let(:example_env) { Rack::MockRequest.env_for("https://www.example.com") }
29
+
30
+ it "succeeds if the credentials are the same" do
31
+ allow(example_credential).to receive(:==).and_return(true)
32
+
33
+ Rails::Auth.add_credential(example_env, example_credential_type, example_credential)
34
+
35
+ expect do
36
+ Rails::Auth.add_credential(example_env, example_credential_type, second_credential)
37
+ end.to_not raise_error
38
+ end
39
+
40
+ it "raises Rails::Auth::AlreadyAuthorizedError if the credentials are different" do
41
+ allow(example_credential).to receive(:==).and_return(false)
42
+
43
+ Rails::Auth.add_credential(example_env, example_credential_type, example_credential)
44
+
26
45
  expect do
27
- credentials[example_credential_type] = example_credential_value
46
+ Rails::Auth.add_credential(example_env, example_credential_type, second_credential)
28
47
  end.to raise_error(Rails::Auth::AlreadyAuthorizedError)
29
48
  end
30
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack