demopass 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: ec269ae22d7a0e5138aeba6ee954fde6f51ead3c02e1cfe23070bbdec59343cb
4
- data.tar.gz: 1fde34f15bb1eed9c1ae52cbd1d3cf4cd38ffc4f87133887b8a095b3204ae475
3
+ metadata.gz: db808df5d6e5cd7a3afda85d10590eaada99da80d94fc2b7a01ef49f32861f21
4
+ data.tar.gz: 3598bd131b0d20e09c5c2dfa584654ba045754b7461f3d069a8bfc9baf74a8fa
5
5
  SHA512:
6
- metadata.gz: d66409aec60d5d756f1668842c65992e2493aa1611e91123214a31298441c4e54e7d1de79724d23714fe74610003ff24f699164f0c7a86ff7b685a1a54ac690d
7
- data.tar.gz: 246085789cdb4fef2fb545cac6d897c1755b2d1b6e7f27d6c9056979d62c9c6d5f7da4b44727a5d91181b571e1efaceec3e727b39ba175636e632791419dfc90
6
+ metadata.gz: fe48a975bcde99459f6c2696e0d93f061ca8c91089956b1b7ff3db3cac1c6385042ff6ecc6ce942528654b0bcd6167d305475a8ec447c03d7130ae3a73166718
7
+ data.tar.gz: 85b8c8cc117e7b2c4737cc70c6b6fa1757ea9c0dc3b3132300680e214bd3d98a3363c4483ecd438b71655768ff663a3c9cc040f544738fa12f3e680d1747062a
data/.rubocop.yml CHANGED
@@ -98,6 +98,12 @@ RSpec/MultipleExpectations:
98
98
  Enabled: false
99
99
  RSpec/ExampleLength:
100
100
  Enabled: false
101
+ RSpec/ContextWording:
102
+ Prefixes:
103
+ - but
104
+ - when
105
+ - with
106
+ - without
101
107
  Metrics/BlockLength:
102
108
  Exclude:
103
109
  - spec/**/*
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- demopass (0.1.0)
4
+ demopass (0.2.0)
5
5
  rack
6
6
 
7
7
  GEM
data/lib/demopass/app.rb CHANGED
@@ -5,22 +5,23 @@ class Demopass::App
5
5
  PASSWORD_KEY = "password".freeze
6
6
  TOKEN_KEY = "demopass_token".freeze
7
7
 
8
- def initialize(downstream)
8
+ def initialize(downstream, except: nil)
9
9
  @downstream = downstream
10
+ @except = except
10
11
  @response = Rack::Response.new
11
12
 
12
13
  @hmac_key = ENV["DEMOPASS_SECRET"]
13
14
  @password = ENV["DEMOPASS_PASSWORD"]
14
15
 
15
- raise Demopass::Error, "Please configure DEMOPASS_SECRET and DEMOPASS_PASSWORD" unless @hmac_key && @password
16
-
17
16
  @digest = OpenSSL::Digest.new("SHA256")
18
17
  @valid_hmac = hmac_for(@password)
18
+
19
+ validate_arguments
19
20
  end
20
21
 
21
22
  def call(env)
22
23
  request = Rack::Request.new(env)
23
- return @downstream.call(env) if token_valid?(request)
24
+ return @downstream.call(env) if path_excluded?(request) || token_valid?(request)
24
25
 
25
26
  if (password = extract_password(request))
26
27
  assign_token_and_redirect(password)
@@ -33,6 +34,10 @@ class Demopass::App
33
34
 
34
35
  private
35
36
 
37
+ def path_excluded?(request)
38
+ @except && request.path =~ @except
39
+ end
40
+
36
41
  def token_valid?(request)
37
42
  request.cookies[TOKEN_KEY] == @valid_hmac
38
43
  end
@@ -74,4 +79,12 @@ private
74
79
  def respond_with_form
75
80
  @response.write(FORM)
76
81
  end
82
+
83
+ def validate_arguments
84
+ if @except && !@except.is_a?(Regexp)
85
+ raise Demopass::Error, "The `except` option must be a regular expression (or blank)."
86
+ end
87
+
88
+ raise Demopass::Error, "Please configure DEMOPASS_SECRET and DEMOPASS_PASSWORD" unless @hmac_key && @password
89
+ end
77
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Demopass
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demopass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Crosby-McCullough
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack