gds-api-adapters 71.0.0 → 71.1.0

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: f43e07de0971fb6d31f613c0e6ecf3894ddc198755ad003da36e6c43e37dedf5
4
- data.tar.gz: 66369531af1d7c4412b79994759e360b78cb67b2e842a3d6f82e10267bd18876
3
+ metadata.gz: 9324b0ac6cf23eff191016dbb952b2cc4507d1071a6d7d8e463ce389f1e38024
4
+ data.tar.gz: d5b157159178227c69d0d724f49f10e299937c7c855c9cc5b55019d9995e17f2
5
5
  SHA512:
6
- metadata.gz: ca1f75189c94449dac72f8e3826b67c36d57e55a40103a69aa2cc48dce9cbc75eff901b060d2d360d301ec482bca4937f5178a57b3b53a1e497bb96ca1a84490
7
- data.tar.gz: 2cca74c89f2a0f827a09917fe6817aeac7199871f1f4c990845668b68c7daff9889dd2f885c809399c732d98b8c074f607072c24db8ad438a287b23f96a5dcb9
6
+ metadata.gz: b24b9dec516dfbd48713c6bee798e1d4579def436e284077f89f649f3ec3dbd0fc88a3b59270c07f3d51f4e972058d6521168d571e263e037de785b4e48af9b7
7
+ data.tar.gz: 37dd29babe5be2b2f11d9fc26ea2d5b3d8e9414779b3d226f6282d533ad57ea9aed10cce07ee2725109ef30885e4707aec4d9c70e7ff818572f644a390bc3ce5
@@ -12,10 +12,17 @@ class GdsApi::AccountApi < GdsApi::Base
12
12
  #
13
13
  # @param [String, nil] redirect_path path on GOV.UK to send the user to after authentication
14
14
  # @param [String, nil] state_id identifier originally returned by #create_registration_state
15
+ # @param [String, nil] level_of_authentication either "level1" (require MFA) or "level0" (do not require MFA)
15
16
  #
16
17
  # @return [Hash] An authentication URL and the OAuth state parameter (for CSRF protection)
17
- def get_sign_in_url(redirect_path: nil, state_id: nil)
18
- querystring = nested_query_string({ redirect_path: redirect_path, state_id: state_id }.compact)
18
+ def get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil)
19
+ querystring = nested_query_string(
20
+ {
21
+ redirect_path: redirect_path,
22
+ state_id: state_id,
23
+ level_of_authentication: level_of_authentication,
24
+ }.compact,
25
+ )
19
26
  get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}")
20
27
  end
21
28
 
@@ -78,6 +85,17 @@ class GdsApi::AccountApi < GdsApi::Base
78
85
  patch_json("#{endpoint}/api/attributes", { attributes: attributes }, auth_headers(govuk_account_session))
79
86
  end
80
87
 
88
+ # Look up the names of a user's attributes
89
+ #
90
+ # @param [String] attributes Names of the attributes to check
91
+ # @param [String] govuk_account_session Value of the session header
92
+ #
93
+ # @return [Hash] The attribute names (if present), and a new session header
94
+ def get_attributes_names(attributes:, govuk_account_session:)
95
+ querystring = nested_query_string({ attributes: attributes }.compact)
96
+ get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
97
+ end
98
+
81
99
  private
82
100
 
83
101
  def nested_query_string(params)
@@ -23,12 +23,13 @@ module GdsApi
23
23
 
24
24
  # Superclass for all 4XX and 5XX errors
25
25
  class HTTPErrorResponse < BaseError
26
- attr_accessor :code, :error_details
26
+ attr_accessor :code, :error_details, :http_body
27
27
 
28
- def initialize(code, message = nil, error_details = nil)
28
+ def initialize(code, message = nil, error_details = nil, http_body = nil)
29
29
  super(message)
30
30
  @code = code
31
31
  @error_details = error_details
32
+ @http_body = http_body
32
33
  end
33
34
  end
34
35
 
@@ -72,7 +73,7 @@ module GdsApi
72
73
  def build_specific_http_error(error, url, details = nil)
73
74
  message = "URL: #{url}\nResponse body:\n#{error.http_body}"
74
75
  code = error.http_code
75
- error_class_for_code(code).new(code, message, details)
76
+ error_class_for_code(code).new(code, message, details, error.http_body)
76
77
  end
77
78
 
78
79
  def error_class_for_code(code)
@@ -89,37 +89,6 @@ class GdsApi::LinkCheckerApi < GdsApi::Base
89
89
  )
90
90
  end
91
91
 
92
- # Update or create a set of links to be monitored for a resource.
93
- #
94
- # Makes a +POST+ request to the link checker api to create a resource monitor.
95
- #
96
- # @param links [Array] A list of URIs to monitor.
97
- # @param reference [String] A unique id for the resource being monitored
98
- # @param app [String] The name of the service the call originated e.g. 'whitehall'
99
- # @return [MonitorReport] A +SimpleDelegator+ of the +GdsApi::Response+ which
100
- # responds to:
101
- # :id the ID of the created resource monitor
102
- #
103
- # @raise [HTTPErrorResponse] if the request returns an error
104
-
105
- def upsert_resource_monitor(links, app, reference)
106
- payload = {
107
- links: links,
108
- app: app,
109
- reference: reference,
110
- }
111
-
112
- response = post_json("#{endpoint}/monitor", payload)
113
-
114
- MonitorReport.new(response.to_hash)
115
- end
116
-
117
- class MonitorReport < SimpleDelegator
118
- def id
119
- self["id"]
120
- end
121
- end
122
-
123
92
  class LinkReport < SimpleDelegator
124
93
  def uri
125
94
  self["uri"]
@@ -5,8 +5,8 @@ module GdsApi
5
5
  module AccountApi
6
6
  ACCOUNT_API_ENDPOINT = Plek.find("account-api")
7
7
 
8
- def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, auth_uri: "http://auth/provider", state: "state")
9
- querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id }.compact)
8
+ def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, level_of_authentication: nil, auth_uri: "http://auth/provider", state: "state")
9
+ querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact)
10
10
  stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
11
11
  .to_return(
12
12
  status: 200,
@@ -38,61 +38,173 @@ module GdsApi
38
38
  )
39
39
  end
40
40
 
41
- def stub_account_api_has_email_subscription(govuk_account_session: nil, new_govuk_account_session: nil)
42
- if govuk_account_session
43
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
44
- .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
45
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: true }.compact.to_json)
46
- else
47
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
48
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: true }.compact.to_json)
49
- end
41
+ def stub_account_api_has_email_subscription(**options)
42
+ stub_account_api_request(
43
+ :get,
44
+ "/api/transition-checker-email-subscription",
45
+ response_body: { has_subscription: true },
46
+ **options,
47
+ )
50
48
  end
51
49
 
52
- def stub_account_api_does_not_have_email_subscription(govuk_account_session: nil, new_govuk_account_session: nil)
53
- if govuk_account_session
54
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
55
- .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
56
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: false }.compact.to_json)
57
- else
58
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
59
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: false }.compact.to_json)
60
- end
50
+ def stub_account_api_does_not_have_email_subscription(**options)
51
+ stub_account_api_request(
52
+ :get,
53
+ "/api/transition-checker-email-subscription",
54
+ response_body: { has_subscription: false },
55
+ **options,
56
+ )
61
57
  end
62
58
 
63
- def stub_account_api_set_email_subscription(govuk_account_session: nil, slug: "slug", new_govuk_account_session: nil)
64
- if govuk_account_session
65
- stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
66
- .with(body: hash_including({ slug: slug }.compact), headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
67
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
68
- else
69
- stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
70
- .with(body: hash_including({ slug: slug }.compact))
71
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
72
- end
59
+ def stub_account_api_unauthorized_get_email_subscription(**options)
60
+ stub_account_api_request(
61
+ :get,
62
+ "/api/transition-checker-email-subscription",
63
+ response_status: 401,
64
+ **options,
65
+ )
66
+ end
67
+
68
+ def stub_account_api_forbidden_get_email_subscription(needed_level_of_authentication: "level1", **options)
69
+ stub_account_api_request(
70
+ :get,
71
+ "/api/transition-checker-email-subscription",
72
+ response_status: 403,
73
+ response_body: { needed_level_of_authentication: needed_level_of_authentication },
74
+ **options,
75
+ )
76
+ end
77
+
78
+ def stub_account_api_set_email_subscription(slug: nil, **options)
79
+ stub_account_api_request(
80
+ :post,
81
+ "/api/transition-checker-email-subscription",
82
+ with: { body: hash_including({ slug: slug }.compact) },
83
+ **options,
84
+ )
73
85
  end
74
86
 
75
- def stub_account_api_has_attributes(govuk_account_session: nil, attributes: [], values: {}, new_govuk_account_session: nil)
87
+ def stub_account_api_unauthorized_set_email_subscription(slug: nil, **options)
88
+ stub_account_api_request(
89
+ :post,
90
+ "/api/transition-checker-email-subscription",
91
+ with: { body: hash_including({ slug: slug }.compact) },
92
+ response_status: 401,
93
+ **options,
94
+ )
95
+ end
96
+
97
+ def stub_account_api_forbidden_set_email_subscription(slug: nil, needed_level_of_authentication: "level1", **options)
98
+ stub_account_api_request(
99
+ :post,
100
+ "/api/transition-checker-email-subscription",
101
+ with: { body: hash_including({ slug: slug }.compact) },
102
+ response_status: 403,
103
+ response_body: { needed_level_of_authentication: needed_level_of_authentication },
104
+ **options,
105
+ )
106
+ end
107
+
108
+ def stub_account_api_has_attributes(attributes: [], values: {}, **options)
76
109
  querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
77
- if govuk_account_session
78
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/attributes?#{querystring}")
79
- .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
80
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, values: values }.compact.to_json)
81
- else
82
- stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/attributes?#{querystring}")
83
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, values: values }.compact.to_json)
84
- end
110
+ stub_account_api_request(
111
+ :get,
112
+ "/api/attributes?#{querystring}",
113
+ response_body: { values: values },
114
+ **options,
115
+ )
116
+ end
117
+
118
+ def stub_account_api_unauthorized_has_attributes(attributes: [], **options)
119
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
120
+ stub_account_api_request(
121
+ :get,
122
+ "/api/attributes?#{querystring}",
123
+ response_status: 401,
124
+ **options,
125
+ )
126
+ end
127
+
128
+ def stub_account_api_forbidden_has_attributes(attributes: [], needed_level_of_authentication: "level1", **options)
129
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
130
+ stub_account_api_request(
131
+ :get,
132
+ "/api/attributes?#{querystring}",
133
+ response_status: 403,
134
+ response_body: { needed_level_of_authentication: needed_level_of_authentication },
135
+ **options,
136
+ )
137
+ end
138
+
139
+ def stub_account_api_set_attributes(attributes: nil, **options)
140
+ stub_account_api_request(
141
+ :patch,
142
+ "/api/attributes",
143
+ with: { body: hash_including({ attributes: attributes }.compact) },
144
+ **options,
145
+ )
146
+ end
147
+
148
+ def stub_account_api_unauthorized_set_attributes(attributes: nil, **options)
149
+ stub_account_api_request(
150
+ :patch,
151
+ "/api/attributes",
152
+ with: { body: hash_including({ attributes: attributes }.compact) },
153
+ response_status: 401,
154
+ **options,
155
+ )
156
+ end
157
+
158
+ def stub_account_api_forbidden_set_attributes(attributes: nil, needed_level_of_authentication: "level1", **options)
159
+ stub_account_api_request(
160
+ :patch,
161
+ "/api/attributes",
162
+ with: { body: hash_including({ attributes: attributes }.compact) },
163
+ response_status: 403,
164
+ response_body: { needed_level_of_authentication: needed_level_of_authentication },
165
+ **options,
166
+ )
167
+ end
168
+
169
+ def stub_account_api_get_attributes_names(attributes: [], **options)
170
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
171
+ stub_account_api_request(
172
+ :get,
173
+ "/api/attributes/names?#{querystring}",
174
+ response_body: { values: attributes },
175
+ **options,
176
+ )
177
+ end
178
+
179
+ def stub_account_api_unauthorized_get_attributes_names(attributes: [], **options)
180
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
181
+ stub_account_api_request(
182
+ :get,
183
+ "/api/attributes/names?#{querystring}",
184
+ response_status: 401,
185
+ **options,
186
+ )
187
+ end
188
+
189
+ def stub_account_api_forbidden_get_attributes_names(attributes: [], needed_level_of_authentication: "level1", **options)
190
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
191
+ stub_account_api_request(
192
+ :get,
193
+ "/api/attributes/names?#{querystring}",
194
+ response_status: 403,
195
+ response_body: { needed_level_of_authentication: needed_level_of_authentication },
196
+ **options,
197
+ )
85
198
  end
86
199
 
87
- def stub_account_api_set_attributes(govuk_account_session: nil, attributes: nil, new_govuk_account_session: nil)
88
- if govuk_account_session
89
- stub_request(:patch, "#{ACCOUNT_API_ENDPOINT}/api/attributes")
90
- .with(body: hash_including({ attributes: attributes }.compact), headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
91
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
200
+ def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
201
+ with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
202
+ new_govuk_account_session = nil if response_status >= 400
203
+ to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
204
+ if with.empty?
205
+ stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
92
206
  else
93
- stub_request(:patch, "#{ACCOUNT_API_ENDPOINT}/api/attributes")
94
- .with(body: hash_including({ attributes: attributes }.compact))
95
- .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
207
+ stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
96
208
  end
97
209
  end
98
210
  end
@@ -72,23 +72,6 @@ module GdsApi
72
72
  headers: { "Content-Type" => "application/json" },
73
73
  )
74
74
  end
75
-
76
- def stub_link_checker_api_upsert_resource_monitor(app:, reference:, links:)
77
- response_body = { id: 1 }.to_json
78
-
79
- request_body = {
80
- links: links,
81
- app: app,
82
- reference: reference,
83
- }.to_json
84
-
85
- stub_request(:post, "#{LINK_CHECKER_API_ENDPOINT}/monitor")
86
- .with(body: request_body)
87
- .to_return(
88
- body: response_body,
89
- headers: { "Content-Type" => "application/json" },
90
- )
91
- end
92
75
  end
93
76
  end
94
77
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "71.0.0".freeze
2
+ VERSION = "71.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 71.0.0
4
+ version: 71.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable