cohesive_marketplace_middleware 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a34773a0133414482f6c51355c2fed3e3a74c115a5c7029311f93273983444a7
4
- data.tar.gz: 13bd370b078dafd52eabb562df66580decd46c69916ff9a315128cc116329847
3
+ metadata.gz: 7f25619e09f201a527087188d66b5f91ceb0a7070c76cfca92db3a39c6c5d4b8
4
+ data.tar.gz: 4624f274f1b9f529af6dd91de378dc193f70c1784c253a1d8a20698eb4913e2e
5
5
  SHA512:
6
- metadata.gz: e7882e14c2094dd1dd41d946596451144b6b2508a0e65af24a3e427257f9820217f9e0fd2c11f1474bcf9743012ddcd6ddd6f928d7ca9dbbdc978fb234cde5e8
7
- data.tar.gz: 949f6ea4cda78f97492afffe2e17bb49db5274b84f68b4d530d533eba603d9058972a25146e48970d4f95cfbfa4e1c212cd5b6e7f9998f8e45e4c073c4d08021
6
+ metadata.gz: 05fc7672e47b2245f696d5422a5477c889694a7e1fafedfe091299f480b4ed51275fe08b4df6b09a2d6adc08b4cc58d56a8ad6607440b794d849d06af0f427a4
7
+ data.tar.gz: e838506ef7409bbe62797c21dc7dc3cd373f6d8ef0261236dd97d080b723a91ce66e48f7bd5e7ef53030cfd434f9532b45165aacd2b8492abacd20a1d97b6abe
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cohesive_marketplace_middleware (0.1.4)
4
+ cohesive_marketplace_middleware (0.1.5)
5
5
  cohesive_marketplace_sdk (~> 0.1.1, >= 0.1.1)
6
6
  jwt (~> 1.5, >= 1.5.0)
7
7
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CohesiveMarketplaceMiddleware
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -9,15 +9,19 @@ COHESIVE_MIDDLEWARE_LOGIN_PATH = "COHESIVE_MIDDLEWARE_LOGIN_PATH"
9
9
  COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT = "/cohesive_login"
10
10
 
11
11
  module CohesiveMarketplaceMiddleware
12
- def getCohesiveAuthDetails(env)
12
+ def self.get_cohesive_auth_details(env)
13
13
  env[AUTH_DETAILS_ENV_KEY]
14
14
  end
15
15
 
16
- def collect_ignore_paths
16
+ def self.collect_ignore_paths
17
17
  # Get the path prefixes to ignore from an environment variable.
18
18
  ignore_path_prefix_string = ENV[COHESIVE_MIDDLEWARE_IGNORE_PATH_PREFIX]
19
- # Split the prefixes into an array.
20
- result = ignore_path_prefix_string.split(",")
19
+ result = []
20
+ if ignore_path_prefix_string && ignore_path_prefix_string != "nil"
21
+ # Split the prefixes into an array.
22
+ result = ignore_path_prefix_string.split(",")
23
+ end
24
+
21
25
  # Output some information for debugging.
22
26
  puts("Cohesive middleware ignoring paths: ", result)
23
27
  result
@@ -31,12 +35,12 @@ module CohesiveMarketplaceMiddleware
31
35
  # @return [void]
32
36
  def initialize(app)
33
37
  @app = app
34
- @ignore_paths = collect_ignore_paths
38
+ @ignore_paths = CohesiveMarketplaceMiddleware.collect_ignore_paths
35
39
  end
36
40
 
37
41
  def call(env)
38
42
  # Check if the current path should be ignored.
39
- if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"].start_with?(prefix) })
43
+ if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"] && env["REQUEST_PATH"].start_with?(prefix) })
40
44
  authorization_header = env["HTTP_AUTHORIZATION"]
41
45
  if authorization_header&.start_with?("Bearer ")
42
46
  token = authorization_header.sub("Bearer ", "")
@@ -62,17 +66,17 @@ module CohesiveMarketplaceMiddleware
62
66
  # @return [void]
63
67
  def initialize(app)
64
68
  @app = app
65
- @ignore_paths = collect_ignore_paths
69
+ @ignore_paths = CohesiveMarketplaceMiddleware.collect_ignore_paths
66
70
 
67
71
  # Get the login redirect URI from an environment variable.
68
72
  @redirect_uri = ENV[COHESIVE_MIDDLEWARE_LOGIN_PATH]
69
73
  # Set a default URI if the environment variable is not set.
70
- if @redirect_uri == ""
74
+ if !@redirect_uri || @redirect_uri == ""
71
75
  @redirect_uri = COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT
72
76
  end
73
77
 
74
78
  # Add the login redirect URI to the list of ignored paths.
75
- @ignore_paths.append(@redirect_uri)
79
+ @ignore_paths = @ignore_paths.append(@redirect_uri)
76
80
 
77
81
  # Output some information for debugging.
78
82
  puts("Cohesive middleware login redirect: ", @redirect_uri)
@@ -85,7 +89,7 @@ module CohesiveMarketplaceMiddleware
85
89
  # @return [Array] A Rack-compatible response triplet.
86
90
  def call(env)
87
91
  # Check if the current path should be ignored.
88
- if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"].start_with?(prefix) })
92
+ if !(@ignore_paths.any? { |prefix| env["REQUEST_PATH"] && prefix && env["REQUEST_PATH"].start_with?(prefix) })
89
93
  # Create a new request object.
90
94
  request = ActionDispatch::Request.new(env)
91
95
  # Get the authentication token from the cookie.
@@ -101,7 +105,7 @@ module CohesiveMarketplaceMiddleware
101
105
  end
102
106
  else
103
107
  # Redirect the user to the login page if the token is missing.
104
- return [301, {"Location" => "/cohesive_login", "Content-Type" => "text/plain"}, ["token not in cookie"]]
108
+ return [301, {"Location" => COHESIVE_MIDDLEWARE_LOGIN_PATH_DEFAULT, "Content-Type" => "text/plain"}, ["token not in cookie"]]
105
109
  end
106
110
  end
107
111
  # Call the next middleware or application in the chain.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohesive_marketplace_middleware
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chinmay Relkar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt