gds-api-adapters 71.1.0 → 71.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/account_api.rb +96 -0
- data/lib/gds_api/email_alert_api.rb +12 -0
- data/lib/gds_api/json_client.rb +4 -4
- data/lib/gds_api/test_helpers/account_api.rb +316 -9
- data/lib/gds_api/test_helpers/email_alert_api.rb +45 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecea9412cb0ad1e32c5b4eac37fd53699b06e7b9612a7033eb23f989e1a013d2
|
4
|
+
data.tar.gz: 311fc8a8a2dc36fc389dd7d0166943dfab092690d5e1ea504b9395fd44a5f2b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255c6879512abcd1c8383d1f4b24799bc408ce04cce55e1cfd1db7365e5e17189d196fa26917283ff411c93b568c824fda237ea683bc9d5d6e56e397c43aaa54
|
7
|
+
data.tar.gz: 1bc48d079cba0ee202697442fd3646718100df7c5e870ff5c17b38ca32802a11fd4f833f424d12dcf6270a98d3be7fd9a067525c0432dc986c771448be91053c
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -45,6 +45,33 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
45
45
|
post_json("#{endpoint}/api/oauth2/state", attributes: attributes)
|
46
46
|
end
|
47
47
|
|
48
|
+
# Get all the information about a user needed to render the account home page
|
49
|
+
#
|
50
|
+
# @param [String] govuk_account_session Value of the session header
|
51
|
+
#
|
52
|
+
# @return [Hash] Information about the user and the services they've used, and a new session header
|
53
|
+
def get_user(govuk_account_session:)
|
54
|
+
get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
|
55
|
+
end
|
56
|
+
|
57
|
+
# Update the user record with privileged information from the auth service. Only the auth service will call this.
|
58
|
+
#
|
59
|
+
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
|
60
|
+
# @param [String, nil] email The user's current
|
61
|
+
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
|
62
|
+
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
|
63
|
+
#
|
64
|
+
# @return [Hash] The user's subject identifier and email attributes
|
65
|
+
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
|
66
|
+
params = {
|
67
|
+
email: email,
|
68
|
+
email_verified: email_verified,
|
69
|
+
has_unconfirmed_email: has_unconfirmed_email,
|
70
|
+
}.compact
|
71
|
+
|
72
|
+
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
|
73
|
+
end
|
74
|
+
|
48
75
|
# Check if a user has an email subscription for the Transition Checker
|
49
76
|
#
|
50
77
|
# @param [String] govuk_account_session Value of the session header
|
@@ -96,6 +123,75 @@ class GdsApi::AccountApi < GdsApi::Base
|
|
96
123
|
get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
|
97
124
|
end
|
98
125
|
|
126
|
+
# Get the details of an account-linked email subscription.
|
127
|
+
#
|
128
|
+
# @param [String] name Name of the subscription
|
129
|
+
# @param [String] govuk_account_session Value of the session header
|
130
|
+
#
|
131
|
+
# @return [Hash] Details of the subscription, if it exists.
|
132
|
+
def get_email_subscription(name:, govuk_account_session:)
|
133
|
+
get_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", auth_headers(govuk_account_session))
|
134
|
+
end
|
135
|
+
|
136
|
+
# Create or update an account-linked email subscription.
|
137
|
+
#
|
138
|
+
# @param [String] name Name of the subscription
|
139
|
+
# @param [String] topic_slug The email-alert-api topic slug to subscribe to
|
140
|
+
# @param [String] govuk_account_session Value of the session header
|
141
|
+
#
|
142
|
+
# @return [Hash] Details of the newly created subscription.
|
143
|
+
def put_email_subscription(name:, topic_slug:, govuk_account_session:)
|
144
|
+
put_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", { topic_slug: topic_slug }, auth_headers(govuk_account_session))
|
145
|
+
end
|
146
|
+
|
147
|
+
# Unsubscribe and delete an account-linked email subscription.
|
148
|
+
#
|
149
|
+
# @param [String] name Name of the subscription
|
150
|
+
# @param [String] govuk_account_session Value of the session header
|
151
|
+
def delete_email_subscription(name:, govuk_account_session:)
|
152
|
+
delete_json("#{endpoint}/api/email-subscriptions/#{CGI.escape(name)}", {}, auth_headers(govuk_account_session))
|
153
|
+
end
|
154
|
+
|
155
|
+
# Look up all pages saved by a user in their Account
|
156
|
+
#
|
157
|
+
# @param [String] govuk_account_session Value of the session header
|
158
|
+
#
|
159
|
+
# @return [Hash] containing :saved_pages, an array of single saved page hashes
|
160
|
+
def get_saved_pages(govuk_account_session:)
|
161
|
+
get_json("#{endpoint}/api/saved-pages", auth_headers(govuk_account_session))
|
162
|
+
end
|
163
|
+
|
164
|
+
# Return a single page by unique URL
|
165
|
+
#
|
166
|
+
# @param [String] the path of a page to check
|
167
|
+
# @param [String] govuk_account_session Value of the session header
|
168
|
+
#
|
169
|
+
# @return [Hash] containing :saved_page, a hash of a single saved page value
|
170
|
+
def get_saved_page(page_path:, govuk_account_session:)
|
171
|
+
get_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
|
172
|
+
end
|
173
|
+
|
174
|
+
# Upsert a single saved page entry in a users account
|
175
|
+
#
|
176
|
+
# @param [String] the path of a page to check
|
177
|
+
# @param [String] govuk_account_session Value of the session header
|
178
|
+
#
|
179
|
+
# @return [Hash] A single saved page value (if sucessful)
|
180
|
+
def save_page(page_path:, govuk_account_session:)
|
181
|
+
put_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
182
|
+
end
|
183
|
+
|
184
|
+
# Delete a single saved page entry from a users account
|
185
|
+
#
|
186
|
+
# @param [String] the path of a page to check
|
187
|
+
# @param [String] govuk_account_session Value of the session header
|
188
|
+
#
|
189
|
+
# @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
|
190
|
+
# A status code of 404 indicates there is no saved page with this path.
|
191
|
+
def delete_saved_page(page_path:, govuk_account_session:)
|
192
|
+
delete_json("#{endpoint}/api/saved-pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
|
193
|
+
end
|
194
|
+
|
99
195
|
private
|
100
196
|
|
101
197
|
def nested_query_string(params)
|
@@ -176,6 +176,18 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
176
176
|
)
|
177
177
|
end
|
178
178
|
|
179
|
+
# Verify a GOV.UK Account-holder has a corresponding subscriber
|
180
|
+
#
|
181
|
+
# @param [string] govuk_account_session The request's session identifier
|
182
|
+
#
|
183
|
+
# @return [Hash] subscriber
|
184
|
+
def authenticate_subscriber_by_govuk_account(govuk_account_session:)
|
185
|
+
post_json(
|
186
|
+
"#{endpoint}/subscribers/govuk-account",
|
187
|
+
govuk_account_session: govuk_account_session,
|
188
|
+
)
|
189
|
+
end
|
190
|
+
|
179
191
|
# Verify a subscriber has control of a provided email
|
180
192
|
#
|
181
193
|
# @param [string] address Address to send verification email to
|
data/lib/gds_api/json_client.rb
CHANGED
@@ -180,10 +180,10 @@ module GdsApi
|
|
180
180
|
raise GdsApi::EndpointNotFound, "Could not connect to #{url}"
|
181
181
|
rescue RestClient::Exceptions::Timeout => e
|
182
182
|
logger.error loggable.merge(status: "timeout", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
|
183
|
-
raise GdsApi::TimedOutException
|
183
|
+
raise GdsApi::TimedOutException, e.message
|
184
184
|
rescue URI::InvalidURIError => e
|
185
185
|
logger.error loggable.merge(status: "invalid_uri", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
|
186
|
-
raise GdsApi::InvalidUrl
|
186
|
+
raise GdsApi::InvalidUrl, e.message
|
187
187
|
rescue RestClient::Exception => e
|
188
188
|
# Log the error here, since we have access to loggable, but raise the
|
189
189
|
# exception up to the calling method to deal with
|
@@ -192,10 +192,10 @@ module GdsApi
|
|
192
192
|
raise
|
193
193
|
rescue Errno::ECONNRESET => e
|
194
194
|
logger.error loggable.merge(status: "connection_reset", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
|
195
|
-
raise GdsApi::TimedOutException
|
195
|
+
raise GdsApi::TimedOutException, e.message
|
196
196
|
rescue SocketError => e
|
197
197
|
logger.error loggable.merge(status: "socket_error", error_message: e.message, error_class: e.class.name, end_time: Time.now.to_f).to_json
|
198
|
-
raise GdsApi::SocketErrorException
|
198
|
+
raise GdsApi::SocketErrorException, e.message
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -5,6 +5,20 @@ module GdsApi
|
|
5
5
|
module AccountApi
|
6
6
|
ACCOUNT_API_ENDPOINT = Plek.find("account-api")
|
7
7
|
|
8
|
+
def stub_account_api_request(method, path, with: {}, response_status: 200, response_body: {}, govuk_account_session: nil, new_govuk_account_session: nil)
|
9
|
+
with.merge!(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session }) if govuk_account_session
|
10
|
+
new_govuk_account_session = nil if response_status >= 400
|
11
|
+
to_return = { status: response_status, body: response_body.merge(govuk_account_session: new_govuk_account_session).compact.to_json }
|
12
|
+
if with.empty?
|
13
|
+
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").to_return(**to_return)
|
14
|
+
else
|
15
|
+
stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#########################
|
20
|
+
# GET /api/oauth2/sign-in
|
21
|
+
#########################
|
8
22
|
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
23
|
querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id, level_of_authentication: level_of_authentication }.compact)
|
10
24
|
stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
|
@@ -14,6 +28,9 @@ module GdsApi
|
|
14
28
|
)
|
15
29
|
end
|
16
30
|
|
31
|
+
###########################
|
32
|
+
# POST /api/oauth2/callback
|
33
|
+
###########################
|
17
34
|
def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id")
|
18
35
|
stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
|
19
36
|
.with(body: hash_including({ code: code, state: state }.compact))
|
@@ -29,6 +46,9 @@ module GdsApi
|
|
29
46
|
.to_return(status: 401)
|
30
47
|
end
|
31
48
|
|
49
|
+
########################
|
50
|
+
# POST /api/oauth2/state
|
51
|
+
########################
|
32
52
|
def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id")
|
33
53
|
stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state")
|
34
54
|
.with(body: hash_including({ attributes: attributes }.compact))
|
@@ -38,6 +58,155 @@ module GdsApi
|
|
38
58
|
)
|
39
59
|
end
|
40
60
|
|
61
|
+
###############
|
62
|
+
# GET /api/user
|
63
|
+
###############
|
64
|
+
def stub_account_api_user_info(level_of_authentication: "level0", email: "email@example.com", email_verified: true, has_unconfirmed_email: false, services: {}, **options)
|
65
|
+
stub_account_api_request(
|
66
|
+
:get,
|
67
|
+
"/api/user",
|
68
|
+
response_body: {
|
69
|
+
level_of_authentication: level_of_authentication,
|
70
|
+
email: email,
|
71
|
+
email_verified: email_verified,
|
72
|
+
has_unconfirmed_email: has_unconfirmed_email,
|
73
|
+
services: services,
|
74
|
+
},
|
75
|
+
**options,
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
def stub_account_api_user_info_service_state(service:, service_state: "yes", **options)
|
80
|
+
stub_account_api_user_info(
|
81
|
+
**options.merge(
|
82
|
+
services: options.fetch(:services, {}).merge(service => service_state),
|
83
|
+
),
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
def stub_account_api_unauthorized_user_info(**options)
|
88
|
+
stub_account_api_request(
|
89
|
+
:get,
|
90
|
+
"/api/user",
|
91
|
+
response_status: 401,
|
92
|
+
**options,
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
###########################################
|
97
|
+
# PATCH /api/oidc-users/:subject_identifier
|
98
|
+
###########################################
|
99
|
+
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil)
|
100
|
+
stub_account_api_request(
|
101
|
+
:patch,
|
102
|
+
"/api/oidc-users/#{subject_identifier}",
|
103
|
+
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
|
104
|
+
response_body: {
|
105
|
+
sub: subject_identifier,
|
106
|
+
email: email || old_email,
|
107
|
+
email_verified: email_verified || old_email_verified,
|
108
|
+
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
|
109
|
+
},
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
####################################
|
114
|
+
# GET /api/email-subscriptions/:name
|
115
|
+
####################################
|
116
|
+
def stub_account_api_get_email_subscription(name:, topic_slug: "slug", email_alert_api_subscription_id: "12345", **options)
|
117
|
+
stub_account_api_request(
|
118
|
+
:get,
|
119
|
+
"/api/email-subscriptions/#{name}",
|
120
|
+
response_body: {
|
121
|
+
email_subscription: {
|
122
|
+
name: name,
|
123
|
+
topic_slug: topic_slug,
|
124
|
+
email_alert_api_subscription_id: email_alert_api_subscription_id,
|
125
|
+
},
|
126
|
+
},
|
127
|
+
**options,
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def stub_account_api_get_email_subscription_does_not_exist(name:, **options)
|
132
|
+
stub_account_api_request(
|
133
|
+
:get,
|
134
|
+
"/api/email-subscriptions/#{name}",
|
135
|
+
response_status: 404,
|
136
|
+
**options,
|
137
|
+
)
|
138
|
+
end
|
139
|
+
|
140
|
+
def stub_account_api_get_email_subscription_unauthorized(name:, **options)
|
141
|
+
stub_account_api_request(
|
142
|
+
:get,
|
143
|
+
"/api/email-subscriptions/#{name}",
|
144
|
+
response_status: 401,
|
145
|
+
**options,
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
####################################
|
150
|
+
# PUT /api/email-subscriptions/:name
|
151
|
+
####################################
|
152
|
+
def stub_account_api_put_email_subscription(name:, topic_slug: nil, **options)
|
153
|
+
stub_account_api_request(
|
154
|
+
:put,
|
155
|
+
"/api/email-subscriptions/#{name}",
|
156
|
+
with: { body: hash_including({ topic_slug: topic_slug }.compact) },
|
157
|
+
response_body: {
|
158
|
+
email_subscription: {
|
159
|
+
name: name,
|
160
|
+
topic_slug: topic_slug || "slug",
|
161
|
+
},
|
162
|
+
},
|
163
|
+
**options,
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
def stub_account_api_unauthorized_put_email_subscription(name:, topic_slug: nil, **options)
|
168
|
+
stub_account_api_request(
|
169
|
+
:put,
|
170
|
+
"/api/email-subscriptions/#{name}",
|
171
|
+
with: { body: hash_including({ topic_slug: topic_slug }.compact) },
|
172
|
+
response_status: 401,
|
173
|
+
**options,
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
#######################################
|
178
|
+
# DELETE /api/email-subscriptions/:name
|
179
|
+
#######################################
|
180
|
+
def stub_account_api_delete_email_subscription(name:, **options)
|
181
|
+
stub_account_api_request(
|
182
|
+
:delete,
|
183
|
+
"/api/email-subscriptions/#{name}",
|
184
|
+
response_status: 204,
|
185
|
+
**options,
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
def stub_account_api_delete_email_subscription_does_not_exist(name:, **options)
|
190
|
+
stub_account_api_request(
|
191
|
+
:delete,
|
192
|
+
"/api/email-subscriptions/#{name}",
|
193
|
+
response_status: 404,
|
194
|
+
**options,
|
195
|
+
)
|
196
|
+
end
|
197
|
+
|
198
|
+
def stub_account_api_unauthorized_delete_email_subscription(name:, **options)
|
199
|
+
stub_account_api_request(
|
200
|
+
:delete,
|
201
|
+
"/api/email-subscriptions/#{name}",
|
202
|
+
response_status: 401,
|
203
|
+
**options,
|
204
|
+
)
|
205
|
+
end
|
206
|
+
|
207
|
+
################################################
|
208
|
+
# GET /api/transition-checker-email-subscription
|
209
|
+
################################################
|
41
210
|
def stub_account_api_has_email_subscription(**options)
|
42
211
|
stub_account_api_request(
|
43
212
|
:get,
|
@@ -75,6 +244,9 @@ module GdsApi
|
|
75
244
|
)
|
76
245
|
end
|
77
246
|
|
247
|
+
#################################################
|
248
|
+
# POST /api/transition-checker-email-subscription
|
249
|
+
#################################################
|
78
250
|
def stub_account_api_set_email_subscription(slug: nil, **options)
|
79
251
|
stub_account_api_request(
|
80
252
|
:post,
|
@@ -105,6 +277,9 @@ module GdsApi
|
|
105
277
|
)
|
106
278
|
end
|
107
279
|
|
280
|
+
#####################
|
281
|
+
# GET /api/attributes
|
282
|
+
#####################
|
108
283
|
def stub_account_api_has_attributes(attributes: [], values: {}, **options)
|
109
284
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
110
285
|
stub_account_api_request(
|
@@ -136,6 +311,9 @@ module GdsApi
|
|
136
311
|
)
|
137
312
|
end
|
138
313
|
|
314
|
+
#######################
|
315
|
+
# PATCH /api/attributes
|
316
|
+
#######################
|
139
317
|
def stub_account_api_set_attributes(attributes: nil, **options)
|
140
318
|
stub_account_api_request(
|
141
319
|
:patch,
|
@@ -166,6 +344,9 @@ module GdsApi
|
|
166
344
|
)
|
167
345
|
end
|
168
346
|
|
347
|
+
###########################
|
348
|
+
# GET /api/attributes/names
|
349
|
+
###########################
|
169
350
|
def stub_account_api_get_attributes_names(attributes: [], **options)
|
170
351
|
querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
|
171
352
|
stub_account_api_request(
|
@@ -197,15 +378,141 @@ module GdsApi
|
|
197
378
|
)
|
198
379
|
end
|
199
380
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
381
|
+
######################
|
382
|
+
# GET /api/saved-pages
|
383
|
+
######################
|
384
|
+
def stub_account_api_returning_saved_pages(saved_pages: [], **options)
|
385
|
+
stub_account_api_request(
|
386
|
+
:get,
|
387
|
+
"/api/saved-pages",
|
388
|
+
response_body: { saved_pages: saved_pages },
|
389
|
+
**options,
|
390
|
+
)
|
391
|
+
end
|
392
|
+
|
393
|
+
def stub_account_api_unauthorized_get_saved_pages(**options)
|
394
|
+
stub_account_api_request(
|
395
|
+
:get,
|
396
|
+
"/api/saved-pages",
|
397
|
+
response_status: 401,
|
398
|
+
**options,
|
399
|
+
)
|
400
|
+
end
|
401
|
+
|
402
|
+
#################################
|
403
|
+
# GET /api/saved_pages/:page_path
|
404
|
+
#################################
|
405
|
+
def stub_account_api_get_saved_page(page_path:, content_id: "46163ed2-1777-4ee6-bdd4-6a2007e49d8f", title: "Ministry of Magic", **options)
|
406
|
+
stub_account_api_request(
|
407
|
+
:get,
|
408
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
409
|
+
response_body: {
|
410
|
+
saved_page: {
|
411
|
+
page_path: page_path,
|
412
|
+
content_id: content_id,
|
413
|
+
title: title,
|
414
|
+
},
|
415
|
+
},
|
416
|
+
**options,
|
417
|
+
)
|
418
|
+
end
|
419
|
+
|
420
|
+
def stub_account_api_does_not_have_saved_page(page_path:, **options)
|
421
|
+
stub_account_api_request(
|
422
|
+
:get,
|
423
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
424
|
+
response_status: 404,
|
425
|
+
**options,
|
426
|
+
)
|
427
|
+
end
|
428
|
+
|
429
|
+
def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
|
430
|
+
stub_account_api_request(
|
431
|
+
:get,
|
432
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
433
|
+
response_status: 401,
|
434
|
+
**options,
|
435
|
+
)
|
436
|
+
end
|
437
|
+
|
438
|
+
#################################
|
439
|
+
# PUT /api/saved-pages/:page_path
|
440
|
+
#################################
|
441
|
+
def stub_account_api_save_page(page_path:, content_id: "c840bfa2-011a-42cc-ac7a-a6da990aff0b", title: "Ministry of Magic", **options)
|
442
|
+
stub_account_api_request(
|
443
|
+
:put,
|
444
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
445
|
+
response_body: {
|
446
|
+
saved_page: {
|
447
|
+
page_path: page_path,
|
448
|
+
content_id: content_id,
|
449
|
+
title: title,
|
450
|
+
},
|
451
|
+
},
|
452
|
+
**options,
|
453
|
+
)
|
454
|
+
end
|
455
|
+
|
456
|
+
def stub_account_api_save_page_already_exists(page_path:, **options)
|
457
|
+
stub_account_api_save_page(page_path: page_path, **options)
|
458
|
+
end
|
459
|
+
|
460
|
+
def stub_account_api_save_page_cannot_save_page(page_path:, **options)
|
461
|
+
stub_account_api_request(
|
462
|
+
:put,
|
463
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
464
|
+
response_status: 422,
|
465
|
+
response_body: cannot_save_page_problem_detail({ page_path: page_path }),
|
466
|
+
**options,
|
467
|
+
)
|
468
|
+
end
|
469
|
+
|
470
|
+
def stub_account_api_unauthorized_save_page(page_path:, **options)
|
471
|
+
stub_account_api_request(
|
472
|
+
:put,
|
473
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
474
|
+
response_status: 401,
|
475
|
+
**options,
|
476
|
+
)
|
477
|
+
end
|
478
|
+
|
479
|
+
def cannot_save_page_problem_detail(option = {})
|
480
|
+
{
|
481
|
+
title: "Cannot save page",
|
482
|
+
detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
|
483
|
+
type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
|
484
|
+
**option,
|
485
|
+
}
|
486
|
+
end
|
487
|
+
|
488
|
+
####################################
|
489
|
+
# DELETE /api/saved-pages/:page_path
|
490
|
+
####################################
|
491
|
+
def stub_account_api_delete_saved_page(page_path:, **options)
|
492
|
+
stub_account_api_request(
|
493
|
+
:delete,
|
494
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
495
|
+
response_status: 204,
|
496
|
+
**options,
|
497
|
+
)
|
498
|
+
end
|
499
|
+
|
500
|
+
def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
|
501
|
+
stub_account_api_request(
|
502
|
+
:delete,
|
503
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
504
|
+
response_status: 404,
|
505
|
+
**options,
|
506
|
+
)
|
507
|
+
end
|
508
|
+
|
509
|
+
def stub_account_api_delete_saved_page_unauthorised(page_path:, **options)
|
510
|
+
stub_account_api_request(
|
511
|
+
:delete,
|
512
|
+
"/api/saved-pages/#{CGI.escape(page_path)}",
|
513
|
+
response_status: 401,
|
514
|
+
**options,
|
515
|
+
)
|
209
516
|
end
|
210
517
|
end
|
211
518
|
end
|
@@ -283,6 +283,51 @@ module GdsApi
|
|
283
283
|
.to_return(status: 404)
|
284
284
|
end
|
285
285
|
|
286
|
+
def stub_email_alert_api_authenticate_subscriber_by_govuk_account(govuk_account_session, subscriber_id, address, new_govuk_account_session: nil)
|
287
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
|
288
|
+
.with(
|
289
|
+
body: { govuk_account_session: govuk_account_session }.to_json,
|
290
|
+
).to_return(
|
291
|
+
status: 200,
|
292
|
+
body: {
|
293
|
+
govuk_account_session: new_govuk_account_session,
|
294
|
+
}.compact.merge(get_subscriber_response(subscriber_id, address)).to_json,
|
295
|
+
)
|
296
|
+
end
|
297
|
+
|
298
|
+
def stub_email_alert_api_authenticate_subscriber_by_govuk_account_session_invalid(govuk_account_session)
|
299
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
|
300
|
+
.with(
|
301
|
+
body: { govuk_account_session: govuk_account_session }.to_json,
|
302
|
+
).to_return(
|
303
|
+
status: 401,
|
304
|
+
)
|
305
|
+
end
|
306
|
+
|
307
|
+
def stub_email_alert_api_authenticate_subscriber_by_govuk_account_email_unverified(govuk_account_session, new_govuk_account_session: nil)
|
308
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
|
309
|
+
.with(
|
310
|
+
body: { govuk_account_session: govuk_account_session }.to_json,
|
311
|
+
).to_return(
|
312
|
+
status: 403,
|
313
|
+
body: {
|
314
|
+
govuk_account_session: new_govuk_account_session,
|
315
|
+
}.compact.to_json,
|
316
|
+
)
|
317
|
+
end
|
318
|
+
|
319
|
+
def stub_email_alert_api_authenticate_subscriber_by_govuk_account_no_subscriber(govuk_account_session, new_govuk_account_session: nil)
|
320
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscribers/govuk-account")
|
321
|
+
.with(
|
322
|
+
body: { govuk_account_session: govuk_account_session }.to_json,
|
323
|
+
).to_return(
|
324
|
+
status: 404,
|
325
|
+
body: {
|
326
|
+
govuk_account_session: new_govuk_account_session,
|
327
|
+
}.compact.to_json,
|
328
|
+
)
|
329
|
+
end
|
330
|
+
|
286
331
|
def assert_unsubscribed(uuid)
|
287
332
|
assert_requested(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unsubscribe/#{uuid}", times: 1)
|
288
333
|
end
|
data/lib/gds_api/version.rb
CHANGED
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.
|
4
|
+
version: 71.6.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-
|
11
|
+
date: 2021-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -445,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
445
445
|
- !ruby/object:Gem::Version
|
446
446
|
version: '0'
|
447
447
|
requirements: []
|
448
|
-
rubygems_version: 3.
|
448
|
+
rubygems_version: 3.0.3
|
449
449
|
signing_key:
|
450
450
|
specification_version: 4
|
451
451
|
summary: Adapters to work with GDS APIs
|