cineworld_uk 3.1.0 → 4.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 +5 -5
- data/.agents/setup +51 -0
- data/.github/workflows/test.yml +43 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +21 -0
- data/README.md +136 -16
- data/Rakefile +5 -37
- data/cineworld_uk.gemspec +7 -4
- data/lib/cineworld_uk/cinema.rb +7 -4
- data/lib/cineworld_uk/internal/api_response.rb +99 -56
- data/lib/cineworld_uk/internal/guest_token.rb +73 -0
- data/lib/cineworld_uk/internal/parser/api/cinema_address.rb +24 -24
- data/lib/cineworld_uk/internal/parser/api/film.rb +10 -8
- data/lib/cineworld_uk/internal/parser/api/performance.rb +6 -11
- data/lib/cineworld_uk/performance.rb +42 -23
- data/lib/cineworld_uk/version.rb +2 -2
- data/lib/cineworld_uk.rb +12 -2
- data/tasks/package.rake +84 -0
- data/test/fixtures/api/cinema-list.json +1 -1
- data/test/fixtures/api/dates-14.json +1 -0
- data/test/fixtures/api/performances-tomorrow-14.json +1 -0
- data/test/fixtures/api/vista-showtimes-brighton.json +1 -0
- data/test/lib/cineworld_uk/cinema_test.rb +47 -47
- data/test/lib/cineworld_uk/internal/api_response_test.rb +177 -58
- data/test/lib/cineworld_uk/internal/parser/api/cinema_address_test.rb +14 -14
- data/test/lib/cineworld_uk/internal/parser/api/film_test.rb +43 -55
- data/test/lib/cineworld_uk/internal/parser/api/performance_test.rb +11 -12
- data/test/lib/cineworld_uk/internal/title_sanitizer_test.rb +18 -18
- data/test/lib/cineworld_uk/performance_test.rb +31 -32
- data/test/lib/cineworld_uk/version_test.rb +1 -1
- data/test/live/integration_test.rb +9 -9
- data/test/package_test.rb +49 -0
- data/test/support/fixture_reader.rb +2 -14
- data/test/test_helper.rb +3 -2
- metadata +65 -36
- data/.travis.yml +0 -10
- data/lib/cineworld_uk/internal/parser/api/film_lookup.rb +0 -38
- data/lib/cineworld_uk/internal/parser/api/performances_by_day.rb +0 -54
- data/test/fixtures/api/cinema-detail-10.json +0 -1
- data/test/fixtures/api/cinema-detail-21.json +0 -1
- data/test/fixtures/api/cinema-detail-3.json +0 -1
- data/test/fixtures/api/cinema-detail-96.json +0 -1
- data/test/fixtures/api/dates-3.json +0 -1
- data/test/fixtures/api/film-list-comingsoon.json +0 -1
- data/test/fixtures/api/film-list.json +0 -1
- data/test/fixtures/api/performances-tomorrow-3.json +0 -1
- data/test/lib/cineworld_uk/internal/parser/api/film_lookup_test.rb +0 -31
|
@@ -17,16 +17,16 @@ describe CineworldUk::Cinema do
|
|
|
17
17
|
|
|
18
18
|
it 'returns an Array of CineworldUK::Cinemas' do
|
|
19
19
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
20
|
-
subject.must_be_instance_of(Array)
|
|
20
|
+
_(subject).must_be_instance_of(Array)
|
|
21
21
|
subject.each do |value|
|
|
22
|
-
value.must_be_instance_of(CineworldUk::Cinema)
|
|
22
|
+
_(value).must_be_instance_of(CineworldUk::Cinema)
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it 'returns the correctly sized array' do
|
|
28
28
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
29
|
-
subject.size.must_equal(
|
|
29
|
+
_(subject.size).must_equal(87)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -35,15 +35,15 @@ describe CineworldUk::Cinema do
|
|
|
35
35
|
subject { described_class.new(id).adr }
|
|
36
36
|
|
|
37
37
|
before do
|
|
38
|
-
api_response.expect(:
|
|
38
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
describe 'Brighton (
|
|
42
|
-
let(:id) {
|
|
41
|
+
describe 'Brighton (14)' do
|
|
42
|
+
let(:id) { 14 }
|
|
43
43
|
|
|
44
44
|
it 'returns the address hash' do
|
|
45
45
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
46
|
-
subject.must_equal(
|
|
46
|
+
_(subject).must_equal(
|
|
47
47
|
street_address: 'Brighton Marina Village',
|
|
48
48
|
extended_address: nil,
|
|
49
49
|
locality: 'Brighton',
|
|
@@ -60,15 +60,15 @@ describe CineworldUk::Cinema do
|
|
|
60
60
|
subject { described_class.new(id).address }
|
|
61
61
|
|
|
62
62
|
before do
|
|
63
|
-
api_response.expect(:
|
|
63
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
describe 'Brighton (
|
|
67
|
-
let(:id) {
|
|
66
|
+
describe 'Brighton (14)' do
|
|
67
|
+
let(:id) { 14 }
|
|
68
68
|
|
|
69
69
|
it 'returns the address hash' do
|
|
70
70
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
71
|
-
subject.must_equal(
|
|
71
|
+
_(subject).must_equal(
|
|
72
72
|
street_address: 'Brighton Marina Village',
|
|
73
73
|
extended_address: nil,
|
|
74
74
|
locality: 'Brighton',
|
|
@@ -85,15 +85,15 @@ describe CineworldUk::Cinema do
|
|
|
85
85
|
subject { described_class.new(id).extended_address }
|
|
86
86
|
|
|
87
87
|
before do
|
|
88
|
-
api_response.expect(:
|
|
88
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
|
-
describe 'Brighton (
|
|
92
|
-
let(:id) {
|
|
91
|
+
describe 'Brighton (14)' do
|
|
92
|
+
let(:id) { 14 }
|
|
93
93
|
|
|
94
94
|
it 'returns the address hash' do
|
|
95
95
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
96
|
-
subject.must_equal('')
|
|
96
|
+
_(subject).must_equal('')
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
end
|
|
@@ -105,31 +105,31 @@ describe CineworldUk::Cinema do
|
|
|
105
105
|
before { api_response.expect(:cinema_list, cinema_list_json) }
|
|
106
106
|
|
|
107
107
|
describe 'simple name (Brighton)' do
|
|
108
|
-
let(:id) {
|
|
108
|
+
let(:id) { 14 }
|
|
109
109
|
|
|
110
110
|
it 'returns the brand in the name' do
|
|
111
111
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
112
|
-
subject.must_equal 'Cineworld Brighton'
|
|
112
|
+
_(subject).must_equal 'Cineworld Brighton'
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
describe 'simple name (Brighton) called with String' do
|
|
118
|
-
let(:id) { '
|
|
118
|
+
let(:id) { '14' }
|
|
119
119
|
|
|
120
120
|
it 'returns the brand in the name' do
|
|
121
121
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
122
|
-
subject.must_equal 'Cineworld Brighton'
|
|
122
|
+
_(subject).must_equal 'Cineworld Brighton'
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
-
describe 'complex name (Glasgow
|
|
127
|
+
describe 'complex name (Glasgow Silverburn)' do
|
|
128
128
|
let(:id) { 88 }
|
|
129
129
|
|
|
130
130
|
it 'returns the brand in the name' do
|
|
131
131
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
132
|
-
subject.must_equal 'Cineworld Glasgow:
|
|
132
|
+
_(subject).must_equal 'Cineworld Glasgow: Silverburn'
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
end
|
|
@@ -139,25 +139,25 @@ describe CineworldUk::Cinema do
|
|
|
139
139
|
subject { described_class.new(id).locality }
|
|
140
140
|
|
|
141
141
|
before do
|
|
142
|
-
api_response.expect(:
|
|
142
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
143
143
|
end
|
|
144
144
|
|
|
145
|
-
describe 'Brighton (
|
|
146
|
-
let(:id) {
|
|
145
|
+
describe 'Brighton (14)' do
|
|
146
|
+
let(:id) { 14 }
|
|
147
147
|
|
|
148
148
|
it 'returns the town/city' do
|
|
149
149
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
150
|
-
subject.must_equal 'Brighton'
|
|
150
|
+
_(subject).must_equal 'Brighton'
|
|
151
151
|
end
|
|
152
152
|
end
|
|
153
153
|
end
|
|
154
154
|
|
|
155
|
-
describe 'London -
|
|
156
|
-
let(:id) {
|
|
155
|
+
describe 'London - Leicester Square (103)' do
|
|
156
|
+
let(:id) { 103 }
|
|
157
157
|
|
|
158
158
|
it 'returns borough of London' do
|
|
159
159
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
160
|
-
subject.must_equal '
|
|
160
|
+
_(subject).must_equal 'London'
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
163
|
end
|
|
@@ -167,15 +167,15 @@ describe CineworldUk::Cinema do
|
|
|
167
167
|
subject { described_class.new(id).postal_code }
|
|
168
168
|
|
|
169
169
|
before do
|
|
170
|
-
api_response.expect(:
|
|
170
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
171
171
|
end
|
|
172
172
|
|
|
173
|
-
describe 'Brighton (
|
|
174
|
-
let(:id) {
|
|
173
|
+
describe 'Brighton (14)' do
|
|
174
|
+
let(:id) { 14 }
|
|
175
175
|
|
|
176
176
|
it 'returns the post code' do
|
|
177
177
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
178
|
-
subject.must_equal 'BN2 5UF'
|
|
178
|
+
_(subject).must_equal 'BN2 5UF'
|
|
179
179
|
end
|
|
180
180
|
end
|
|
181
181
|
end
|
|
@@ -185,25 +185,25 @@ describe CineworldUk::Cinema do
|
|
|
185
185
|
subject { described_class.new(id).region }
|
|
186
186
|
|
|
187
187
|
before do
|
|
188
|
-
api_response.expect(:
|
|
188
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
189
189
|
end
|
|
190
190
|
|
|
191
|
-
describe 'no region - Brighton (
|
|
192
|
-
let(:id) {
|
|
191
|
+
describe 'no region - Brighton (14)' do
|
|
192
|
+
let(:id) { 14 }
|
|
193
193
|
|
|
194
194
|
it 'returns the empty string is none exists' do
|
|
195
195
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
196
|
-
subject.must_equal ''
|
|
196
|
+
_(subject).must_equal ''
|
|
197
197
|
end
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
-
describe 'London -
|
|
202
|
-
let(:id) {
|
|
201
|
+
describe 'London - Leicester Square (103)' do
|
|
202
|
+
let(:id) { 103 }
|
|
203
203
|
|
|
204
204
|
it 'returns "London"' do
|
|
205
205
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
206
|
-
subject.must_equal 'London'
|
|
206
|
+
_(subject).must_equal 'London'
|
|
207
207
|
end
|
|
208
208
|
end
|
|
209
209
|
end
|
|
@@ -213,15 +213,15 @@ describe CineworldUk::Cinema do
|
|
|
213
213
|
subject { described_class.new(id).street_address }
|
|
214
214
|
|
|
215
215
|
before do
|
|
216
|
-
api_response.expect(:
|
|
216
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
-
describe 'Brighton (
|
|
220
|
-
let(:id) {
|
|
219
|
+
describe 'Brighton (14)' do
|
|
220
|
+
let(:id) { 14 }
|
|
221
221
|
|
|
222
222
|
it 'returns the first line of the Address' do
|
|
223
223
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
224
|
-
subject.must_equal 'Brighton Marina Village'
|
|
224
|
+
_(subject).must_equal 'Brighton Marina Village'
|
|
225
225
|
end
|
|
226
226
|
end
|
|
227
227
|
end
|
|
@@ -231,15 +231,15 @@ describe CineworldUk::Cinema do
|
|
|
231
231
|
subject { described_class.new(id).url }
|
|
232
232
|
|
|
233
233
|
before do
|
|
234
|
-
api_response.expect(:
|
|
234
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
235
235
|
end
|
|
236
236
|
|
|
237
|
-
describe 'Brighton (
|
|
238
|
-
let(:id) {
|
|
237
|
+
describe 'Brighton (14)' do
|
|
238
|
+
let(:id) { 14 }
|
|
239
239
|
|
|
240
240
|
it 'returns the url' do
|
|
241
241
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
242
|
-
subject.must_equal(
|
|
242
|
+
_(subject).must_equal(
|
|
243
243
|
"http://www.cineworld.co.uk/cinemas/#{id}/information"
|
|
244
244
|
)
|
|
245
245
|
end
|
|
@@ -1,88 +1,207 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../../../test_helper"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
# This block groups independent Minitest cases, not application logic.
|
|
7
|
+
describe "Vista retrieval" do # rubocop:disable Metrics/BlockLength
|
|
8
|
+
before do
|
|
9
|
+
CineworldUk.token = "test-guest-token"
|
|
10
|
+
[CineworldUk::Cinema, CineworldUk::Performance].each do |klass|
|
|
11
|
+
klass.instance_variables.each do |name|
|
|
12
|
+
klass.remove_instance_variable(name)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
fixture = "../../../fixtures/api/vista-showtimes-brighton.json"
|
|
16
|
+
@capture = JSON.parse(File.read(File.expand_path(fixture, __dir__)))
|
|
17
|
+
@base = "https://digital-api.cineworld.co.uk/ocapi/v1/"
|
|
18
|
+
sites = @capture.fetch("relatedData").fetch("sites")
|
|
19
|
+
stub_request(:get, @base + "sites").with(
|
|
20
|
+
headers: {
|
|
21
|
+
"Authorization" => "Bearer test-guest-token",
|
|
22
|
+
"Connect-Region-Code" => "GB"
|
|
23
|
+
}
|
|
24
|
+
).to_return(body: JSON.generate("sites" => sites))
|
|
25
|
+
end
|
|
6
26
|
|
|
7
|
-
|
|
8
|
-
|
|
27
|
+
after do
|
|
28
|
+
CineworldUk.token = nil
|
|
29
|
+
[CineworldUk::Cinema, CineworldUk::Performance].each do |klass|
|
|
30
|
+
klass.instance_variables.each do |name|
|
|
31
|
+
klass.remove_instance_variable(name)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
9
35
|
|
|
10
|
-
|
|
11
|
-
|
|
36
|
+
def stub_day(day, body)
|
|
37
|
+
stub_request(:get, @base + "showtimes/by-business-date/#{day}").with(
|
|
38
|
+
query: { "siteIds" => "014" },
|
|
39
|
+
headers: { "Authorization" => "Bearer test-guest-token",
|
|
40
|
+
"Connect-Region-Code" => "GB" }
|
|
41
|
+
).to_return(body: JSON.generate(body))
|
|
42
|
+
end
|
|
12
43
|
|
|
13
|
-
|
|
14
|
-
|
|
44
|
+
it "retrieves cinemas and advertised session times from Vista" do
|
|
45
|
+
stub_day("2026-10-14", @capture)
|
|
46
|
+
cinema = CineworldUk::Cinema.all.first
|
|
47
|
+
_(cinema.id).must_equal 14
|
|
48
|
+
_(cinema.name).must_equal "Brighton"
|
|
49
|
+
_(cinema.postal_code).must_equal "BN2 5UF"
|
|
50
|
+
_(cinema.street_address).must_equal "Brighton Marina Village"
|
|
51
|
+
assert_requested :get, @base + "sites", times: 1
|
|
52
|
+
performances = CineworldUk::Performance.at(
|
|
53
|
+
14, from: Date.new(2026, 10, 14), to: Date.new(2026, 10, 14)
|
|
54
|
+
)
|
|
55
|
+
_(performances.size).must_equal 17
|
|
56
|
+
first = performances.first
|
|
57
|
+
_(first.film_name).must_equal "Other Mommy"
|
|
58
|
+
_(first.starting_at).must_equal Time.utc(2026, 10, 14, 14, 40)
|
|
59
|
+
_(first.booking_url).must_equal(
|
|
60
|
+
"https://web.cineworld.co.uk/order/showtimes/014-165507/seats"
|
|
61
|
+
)
|
|
62
|
+
_(first.variant).must_include "audio_described"
|
|
63
|
+
_(first.dimension).must_equal "2d"
|
|
64
|
+
assert_requested :get, @base + "sites", times: 1
|
|
65
|
+
assert_requested :get, @base + "showtimes/by-business-date/2026-10-14",
|
|
66
|
+
query: { "siteIds" => "014" }, times: 1
|
|
67
|
+
end
|
|
15
68
|
|
|
16
|
-
|
|
69
|
+
it "keeps format session-specific and includes the last requested day" do
|
|
70
|
+
@capture["showtimes"] =
|
|
71
|
+
[@capture["showtimes"].first,
|
|
72
|
+
Marshal.load(Marshal.dump(@capture["showtimes"].first))]
|
|
73
|
+
@capture["showtimes"][1]["id"] = "014-second"
|
|
74
|
+
@capture["showtimes"][1]["requires3dGlasses"] = true
|
|
75
|
+
@capture["showtimes"][1]["schedule"]["startsAt"] =
|
|
76
|
+
"2026-10-25T16:40:00+00:00"
|
|
77
|
+
stub_day("2026-10-24",
|
|
78
|
+
"showtimes" => [],
|
|
79
|
+
"relatedData" => { "films" => [], "attributes" => [],
|
|
80
|
+
"sites" => [] })
|
|
81
|
+
stub_day("2026-10-25", @capture)
|
|
82
|
+
results = CineworldUk::Performance.at("014", from: Date.new(2026, 10, 24),
|
|
83
|
+
to: Date.new(2026, 10, 25))
|
|
84
|
+
_(results.map(&:dimension)).must_equal %w[2d 3d]
|
|
85
|
+
_(results.last.starting_at).must_equal Time.utc(2026, 10, 25, 16, 40)
|
|
86
|
+
_(results.first.cinema_name).must_equal "Brighton"
|
|
87
|
+
assert_not_requested :get, @base + "sites"
|
|
88
|
+
end
|
|
17
89
|
|
|
18
|
-
|
|
19
|
-
|
|
90
|
+
it "rejects missing and rejected tokens without exposing credentials" do
|
|
91
|
+
CineworldUk.token = nil
|
|
92
|
+
assert_raises(CineworldUk::AuthenticationError) { CineworldUk::Cinema.all }
|
|
93
|
+
CineworldUk.token = "expired-secret"
|
|
94
|
+
stub_request(:get, @base + "sites").to_return(status: 401,
|
|
95
|
+
body: "expired-secret")
|
|
96
|
+
error = assert_raises(CineworldUk::AuthenticationError) do
|
|
97
|
+
CineworldUk::Cinema.all
|
|
20
98
|
end
|
|
99
|
+
refute_includes error.message, "expired-secret"
|
|
100
|
+
CineworldUk.token = "replacement"
|
|
101
|
+
stub_request(:get, @base + "sites").with(
|
|
102
|
+
headers: { "Authorization" => "Bearer replacement" }
|
|
103
|
+
).to_return(body: '{"sites":[]}')
|
|
104
|
+
_(CineworldUk::Cinema.all).must_equal []
|
|
21
105
|
end
|
|
22
106
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
107
|
+
it "defaults to fourteen days and rejects reversed ranges" do
|
|
108
|
+
day = Date.new(2026, 10, 14)
|
|
109
|
+
(day..day + 13).each do |date|
|
|
110
|
+
stub_day(date.iso8601,
|
|
111
|
+
"showtimes" => [],
|
|
112
|
+
"relatedData" => { "films" => [], "attributes" => [],
|
|
113
|
+
"sites" => [] })
|
|
28
114
|
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
115
|
+
_(CineworldUk::Performance.at(14, from: day)).must_equal []
|
|
116
|
+
assert_requested :get, %r{showtimes/by-business-date/}, times: 14
|
|
117
|
+
assert_raises(ArgumentError) do
|
|
118
|
+
CineworldUk::Performance.at(14, from: day, to: day - 1)
|
|
32
119
|
end
|
|
120
|
+
assert_not_requested :get, @base + "sites"
|
|
33
121
|
end
|
|
34
122
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
123
|
+
it "does not follow redirects or hide forbidden responses" do
|
|
124
|
+
[302, 403].each do |status|
|
|
125
|
+
stub_request(:get, @base + "sites").to_return(
|
|
126
|
+
status: status, headers: { "Location" => "https://example.com/" }
|
|
127
|
+
)
|
|
128
|
+
error = assert_raises(RuntimeError) { CineworldUk::Cinema.all }
|
|
129
|
+
assert_includes error.message, status.to_s
|
|
42
130
|
end
|
|
43
131
|
end
|
|
132
|
+
end
|
|
44
133
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
134
|
+
describe "Guest token acquisition" do
|
|
135
|
+
before do
|
|
136
|
+
@directory = Dir.mktmpdir("cineworld token ")
|
|
137
|
+
@curl = File.join(@directory, "curl-impersonate")
|
|
138
|
+
CineworldUk.token = "existing-token"
|
|
139
|
+
end
|
|
49
140
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
141
|
+
after do
|
|
142
|
+
FileUtils.remove_entry(@directory)
|
|
143
|
+
CineworldUk.token = nil
|
|
53
144
|
end
|
|
54
145
|
|
|
55
|
-
|
|
56
|
-
|
|
146
|
+
def serve_token_page(html, status: 200, exit_code: 0)
|
|
147
|
+
output = "#{html}\n#{status}"
|
|
148
|
+
File.write(@curl, "#!#{RbConfig.ruby}\nSTDOUT.write(#{output.dump})\nexit #{exit_code}\n")
|
|
149
|
+
File.chmod(0o700, @curl)
|
|
150
|
+
end
|
|
57
151
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
152
|
+
def token_page(expires)
|
|
153
|
+
payload = Base64.urlsafe_encode64(JSON.generate("exp" => expires), padding: false)
|
|
154
|
+
token = "header.#{payload}.signature"
|
|
155
|
+
data = { "props" => { "pageProps" => { "environment" => { "gasToken" => token } } } }
|
|
156
|
+
["<script type='application/json' id='__NEXT_DATA__'>#{JSON.generate(data)}</script>", token]
|
|
157
|
+
end
|
|
62
158
|
|
|
63
|
-
|
|
64
|
-
|
|
159
|
+
it "sets and returns the guest JWT from either a 200 or 404 page" do
|
|
160
|
+
html, token = token_page(Time.now.to_i + 3600)
|
|
161
|
+
[200, 404].each do |status|
|
|
162
|
+
serve_token_page(html, status: status)
|
|
163
|
+
_(CineworldUk.acquire_token!(curl: @curl)).must_equal token
|
|
164
|
+
_(CineworldUk.token).must_equal token
|
|
65
165
|
end
|
|
66
166
|
end
|
|
67
167
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
168
|
+
it "rejects expired tokens including the expiry boundary without replacing the current token" do
|
|
169
|
+
now = Time.at(1_800_000_000)
|
|
170
|
+
Time.stub(:now, now) do
|
|
171
|
+
[-1, 0, 1].each do |offset|
|
|
172
|
+
html, token = token_page(now.to_i + offset)
|
|
173
|
+
serve_token_page(html)
|
|
174
|
+
if offset.positive?
|
|
175
|
+
_(CineworldUk.acquire_token!(curl: @curl)).must_equal token
|
|
176
|
+
else
|
|
177
|
+
assert_raises(CineworldUk::AuthenticationError) { CineworldUk.acquire_token!(curl: @curl) }
|
|
178
|
+
_(CineworldUk.token).must_equal "existing-token"
|
|
179
|
+
end
|
|
180
|
+
end
|
|
74
181
|
end
|
|
182
|
+
end
|
|
75
183
|
|
|
76
|
-
|
|
77
|
-
|
|
184
|
+
it "reports blocked, redirected, missing and malformed page data without exposing the response" do
|
|
185
|
+
html, token = token_page(Time.now.to_i + 3600)
|
|
186
|
+
invalid_payload = Base64.urlsafe_encode64("broken-secret", padding: false)
|
|
187
|
+
[[html, 403], [html, 302], ["Cloudflare block", 200],
|
|
188
|
+
["<script id='__NEXT_DATA__'>{</script>", 200],
|
|
189
|
+
["<script id='__NEXT_DATA__'>{}</script>", 200],
|
|
190
|
+
[html.sub(token, "broken-secret"), 200],
|
|
191
|
+
[html.sub(token, "header.#{invalid_payload}.signature"), 200]].each do |body, status|
|
|
192
|
+
serve_token_page(body, status: status)
|
|
193
|
+
error = assert_raises(CineworldUk::AuthenticationError) { CineworldUk.acquire_token!(curl: @curl) }
|
|
194
|
+
refute_includes error.full_message, token
|
|
195
|
+
refute_includes error.full_message, "broken-secret"
|
|
196
|
+
_(CineworldUk.token).must_equal "existing-token"
|
|
78
197
|
end
|
|
79
198
|
end
|
|
80
199
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
200
|
+
it "reports a missing executable or curl failure as an authentication error" do
|
|
201
|
+
error = assert_raises(CineworldUk::AuthenticationError) { CineworldUk.acquire_token!(curl: @curl) }
|
|
202
|
+
assert_includes error.message, "Install curl-impersonate"
|
|
203
|
+
serve_token_page("", status: 0, exit_code: 28)
|
|
204
|
+
error = assert_raises(CineworldUk::AuthenticationError) { CineworldUk.acquire_token!(curl: @curl) }
|
|
205
|
+
assert_includes error.message, "curl exit 28"
|
|
87
206
|
end
|
|
88
207
|
end
|
|
@@ -14,15 +14,15 @@ describe CineworldUk::Internal::Parser::Api::CinemaAddress do
|
|
|
14
14
|
subject { described_class.new(id).to_hash }
|
|
15
15
|
|
|
16
16
|
before do
|
|
17
|
-
api_response.expect(:
|
|
17
|
+
api_response.expect(:cinema_list, cinema_list_json)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
describe 'passed simple (Brighton)' do
|
|
21
|
-
let(:id) {
|
|
21
|
+
let(:id) { 14 }
|
|
22
22
|
|
|
23
23
|
it 'returns address hash' do
|
|
24
24
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
25
|
-
subject.must_equal(street_address: 'Brighton Marina Village',
|
|
25
|
+
_(subject).must_equal(street_address: 'Brighton Marina Village',
|
|
26
26
|
extended_address: nil,
|
|
27
27
|
locality: 'Brighton',
|
|
28
28
|
region: nil,
|
|
@@ -33,11 +33,11 @@ describe CineworldUk::Internal::Parser::Api::CinemaAddress do
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
describe 'passed three line (NEC)' do
|
|
36
|
-
let(:id) {
|
|
36
|
+
let(:id) { 90 }
|
|
37
37
|
|
|
38
38
|
it 'returns address hash' do
|
|
39
39
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
40
|
-
subject.must_equal(street_address: 'Resorts World',
|
|
40
|
+
_(subject).must_equal(street_address: 'Resorts World',
|
|
41
41
|
extended_address: 'Pendigo Way',
|
|
42
42
|
locality: 'Birmingham',
|
|
43
43
|
region: nil,
|
|
@@ -48,11 +48,11 @@ describe CineworldUk::Internal::Parser::Api::CinemaAddress do
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
describe 'passed three line (Edinburgh)' do
|
|
51
|
-
let(:id) {
|
|
51
|
+
let(:id) { 37 }
|
|
52
52
|
|
|
53
53
|
it 'returns address hash' do
|
|
54
54
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
55
|
-
subject.must_equal(street_address: 'Fountain Park',
|
|
55
|
+
_(subject).must_equal(street_address: 'Fountain Park',
|
|
56
56
|
extended_address: '130/3 Dundee Street',
|
|
57
57
|
locality: 'Edinburgh',
|
|
58
58
|
region: nil,
|
|
@@ -62,16 +62,16 @@ describe CineworldUk::Internal::Parser::Api::CinemaAddress do
|
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
describe 'passed
|
|
66
|
-
let(:id) {
|
|
65
|
+
describe 'passed two line (Leicester Square)' do
|
|
66
|
+
let(:id) { 103 }
|
|
67
67
|
|
|
68
68
|
it 'returns address hash' do
|
|
69
69
|
CineworldUk::Internal::ApiResponse.stub :new, api_response do
|
|
70
|
-
subject.must_equal(street_address: '
|
|
70
|
+
_(subject).must_equal(street_address: '5-6 Leicester Square',
|
|
71
71
|
extended_address: nil,
|
|
72
|
-
locality: '
|
|
72
|
+
locality: 'London',
|
|
73
73
|
region: 'London',
|
|
74
|
-
postal_code: '
|
|
74
|
+
postal_code: 'WC2H 7NA',
|
|
75
75
|
country: 'United Kingdom')
|
|
76
76
|
end
|
|
77
77
|
end
|
|
@@ -81,8 +81,8 @@ describe CineworldUk::Internal::Parser::Api::CinemaAddress do
|
|
|
81
81
|
# let(:id) { 0 }
|
|
82
82
|
#
|
|
83
83
|
# it 'returns hash of nils' do
|
|
84
|
-
# subject.must_be_instance_of(Hash)
|
|
85
|
-
# subject.must_equal(street_address: nil,
|
|
84
|
+
# _(subject).must_be_instance_of(Hash)
|
|
85
|
+
# _(subject).must_equal(street_address: nil,
|
|
86
86
|
# extended_address: nil,
|
|
87
87
|
# locality: "not an address",
|
|
88
88
|
# region: nil,
|