flipper-cloud 0.20.0 → 0.20.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flipper/cloud/middleware.rb +14 -4
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/cloud/middleware_spec.rb +77 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35dc166068996854a78fc08810a942999539735d61f8f0215d6c10101a57d23d
|
4
|
+
data.tar.gz: bdccf48ff9d058fc20ded13e1c64d7f64964c2daad12fe0ccc11b8aafcd2d0ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2f6190b1ff9a30ce518a0044323c55a9997db8cf3ec383c4d425ce5eb02121e99a355ca370928df1b9a23ea5add521133fb30a051b56a93b8ce088707d1f2a3
|
7
|
+
data.tar.gz: 132a9a42b22803fa362b85acfd1c741519ce7eff91d5443bf47b8d0d869cd29d6a161ded0e15ef80fa7a642d46b948a454a0c633a72ff5cbbc22949dd2459622
|
@@ -32,10 +32,20 @@ module Flipper
|
|
32
32
|
begin
|
33
33
|
message_verifier = MessageVerifier.new(secret: flipper.sync_secret)
|
34
34
|
if message_verifier.verify(payload, signature)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
begin
|
36
|
+
flipper.sync
|
37
|
+
body = JSON.generate({
|
38
|
+
groups: Flipper.group_names.map { |name| {name: name}}
|
39
|
+
})
|
40
|
+
rescue Flipper::Adapters::Http::Error => error
|
41
|
+
status = error.response.code.to_i == 402 ? 402 : 500
|
42
|
+
headers["Flipper-Cloud-Response-Error-Class"] = error.class.name
|
43
|
+
headers["Flipper-Cloud-Response-Error-Message"] = error.message
|
44
|
+
rescue => error
|
45
|
+
status = 500
|
46
|
+
headers["Flipper-Cloud-Response-Error-Class"] = error.class.name
|
47
|
+
headers["Flipper-Cloud-Response-Error-Message"] = error.message
|
48
|
+
end
|
39
49
|
end
|
40
50
|
rescue MessageVerifier::InvalidSignature
|
41
51
|
status = 400
|
data/lib/flipper/version.rb
CHANGED
@@ -87,6 +87,75 @@ RSpec.describe Flipper::Cloud::Middleware do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
context "when flipper cloud responds with 402" do
|
91
|
+
let(:app) { Flipper::Cloud.app(flipper) }
|
92
|
+
|
93
|
+
it "results in 402" do
|
94
|
+
Flipper.register(:admins) { |*args| false }
|
95
|
+
Flipper.register(:staff) { |*args| false }
|
96
|
+
Flipper.register(:basic) { |*args| false }
|
97
|
+
Flipper.register(:plus) { |*args| false }
|
98
|
+
Flipper.register(:premium) { |*args| false }
|
99
|
+
|
100
|
+
stub = stub_request_for_token('regular', status: 402)
|
101
|
+
env = {
|
102
|
+
"HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
|
103
|
+
}
|
104
|
+
post '/webhooks', request_body, env
|
105
|
+
|
106
|
+
expect(last_response.status).to eq(402)
|
107
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
|
108
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to eq("Failed with status: 402")
|
109
|
+
expect(stub).to have_been_requested
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when flipper cloud responds with non-402 and non-2xx code" do
|
114
|
+
let(:app) { Flipper::Cloud.app(flipper) }
|
115
|
+
|
116
|
+
it "results in 500" do
|
117
|
+
Flipper.register(:admins) { |*args| false }
|
118
|
+
Flipper.register(:staff) { |*args| false }
|
119
|
+
Flipper.register(:basic) { |*args| false }
|
120
|
+
Flipper.register(:plus) { |*args| false }
|
121
|
+
Flipper.register(:premium) { |*args| false }
|
122
|
+
|
123
|
+
stub = stub_request_for_token('regular', status: 503)
|
124
|
+
env = {
|
125
|
+
"HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
|
126
|
+
}
|
127
|
+
post '/webhooks', request_body, env
|
128
|
+
|
129
|
+
expect(last_response.status).to eq(500)
|
130
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Flipper::Adapters::Http::Error")
|
131
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to eq("Failed with status: 503")
|
132
|
+
expect(stub).to have_been_requested
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when flipper cloud responds with timeout" do
|
137
|
+
let(:app) { Flipper::Cloud.app(flipper) }
|
138
|
+
|
139
|
+
it "results in 500" do
|
140
|
+
Flipper.register(:admins) { |*args| false }
|
141
|
+
Flipper.register(:staff) { |*args| false }
|
142
|
+
Flipper.register(:basic) { |*args| false }
|
143
|
+
Flipper.register(:plus) { |*args| false }
|
144
|
+
Flipper.register(:premium) { |*args| false }
|
145
|
+
|
146
|
+
stub = stub_request_for_token('regular', status: :timeout)
|
147
|
+
env = {
|
148
|
+
"HTTP_FLIPPER_CLOUD_SIGNATURE" => signature_header_value,
|
149
|
+
}
|
150
|
+
post '/webhooks', request_body, env
|
151
|
+
|
152
|
+
expect(last_response.status).to eq(500)
|
153
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Class"]).to eq("Net::OpenTimeout")
|
154
|
+
expect(last_response.headers["Flipper-Cloud-Response-Error-Message"]).to eq("execution expired")
|
155
|
+
expect(stub).to have_been_requested
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
90
159
|
context 'when initialized with flipper instance and flipper instance in env' do
|
91
160
|
let(:app) { Flipper::Cloud.app(flipper) }
|
92
161
|
let(:signature) {
|
@@ -177,12 +246,17 @@ RSpec.describe Flipper::Cloud::Middleware do
|
|
177
246
|
|
178
247
|
private
|
179
248
|
|
180
|
-
def stub_request_for_token(token)
|
181
|
-
stub_request(:get, "https://www.flippercloud.io/adapter/features").
|
249
|
+
def stub_request_for_token(token, status: 200)
|
250
|
+
stub = stub_request(:get, "https://www.flippercloud.io/adapter/features").
|
182
251
|
with({
|
183
252
|
headers: {
|
184
253
|
'Flipper-Cloud-Token' => token,
|
185
254
|
},
|
186
|
-
})
|
255
|
+
})
|
256
|
+
if status == :timeout
|
257
|
+
stub.to_timeout
|
258
|
+
else
|
259
|
+
stub.to_return(status: status, body: response_body, headers: {})
|
260
|
+
end
|
187
261
|
end
|
188
262
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.20.
|
4
|
+
version: 0.20.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flipper
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.20.
|
19
|
+
version: 0.20.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.20.
|
26
|
+
version: 0.20.1
|
27
27
|
description:
|
28
28
|
email:
|
29
29
|
- nunemaker@gmail.com
|