txgh-server 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f70d20e0073d7671f6010e1dfd962c7e4758482d
|
4
|
+
data.tar.gz: 9d1167e2d2b25fdbde79051bc93c32535d3fec04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a6abf97a38ed2e92d887ff03e38b5c4327f89816d3c8e87a99ec8f0300326262568f9c5755d08f4451b54fbafe652110dd7685b4c36c4464ffd8c8aa658920
|
7
|
+
data.tar.gz: 25147bc9bd2612a674869236fd13eb78b74aacb58edaf6e5bae058cfa6a97d789d314f21bb62c86ca5fb0840a3ec401153596e4e812058c76918b1cec9d567d5
|
@@ -11,7 +11,7 @@ module TxghServer
|
|
11
11
|
def authentic_request?(request, secret)
|
12
12
|
request.body.rewind
|
13
13
|
expected_signature = header_value(request.body.read, secret)
|
14
|
-
actual_signature = request
|
14
|
+
actual_signature = signature_from(request)
|
15
15
|
actual_signature == expected_signature
|
16
16
|
end
|
17
17
|
|
@@ -19,6 +19,10 @@ module TxghServer
|
|
19
19
|
digest(transform(content), secret)
|
20
20
|
end
|
21
21
|
|
22
|
+
def signature_from(request)
|
23
|
+
request.env[RACK_HEADER]
|
24
|
+
end
|
25
|
+
|
22
26
|
private
|
23
27
|
|
24
28
|
# In order to generate a correct HMAC hash, the request body must be
|
data/lib/txgh-server/version.rb
CHANGED
@@ -20,6 +20,8 @@ module TxghServer
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def handle_request
|
23
|
+
publish_event
|
24
|
+
|
23
25
|
handle_safely do
|
24
26
|
handler = TxghServer::Webhooks::Transifex::HookHandler.new(
|
25
27
|
project: config.transifex_project,
|
@@ -35,6 +37,16 @@ module TxghServer
|
|
35
37
|
|
36
38
|
private
|
37
39
|
|
40
|
+
def publish_event
|
41
|
+
Txgh.events.publish(
|
42
|
+
'transifex.webhook_received', {
|
43
|
+
payload: payload,
|
44
|
+
raw_payload: raw_payload,
|
45
|
+
signature: TransifexRequestAuth.signature_from(request)
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
38
50
|
def handle_safely
|
39
51
|
if authentic_request?
|
40
52
|
yield
|
@@ -63,12 +75,17 @@ module TxghServer
|
|
63
75
|
@config ||= Txgh::Config::KeyManager.config_from_project(payload[:project])
|
64
76
|
end
|
65
77
|
|
66
|
-
def
|
67
|
-
@
|
78
|
+
def raw_payload
|
79
|
+
@raw_payload ||= begin
|
68
80
|
request.body.rewind
|
81
|
+
request.body.read
|
82
|
+
end
|
83
|
+
end
|
69
84
|
|
85
|
+
def payload
|
86
|
+
@payload ||= begin
|
70
87
|
Txgh::Utils.deep_symbolize_keys(
|
71
|
-
Hash[URI.decode_www_form(
|
88
|
+
Hash[URI.decode_www_form(raw_payload)]
|
72
89
|
)
|
73
90
|
end
|
74
91
|
end
|
@@ -10,11 +10,24 @@ describe Transifex::RequestHandler do
|
|
10
10
|
|
11
11
|
let(:logger) { NilLogger.new }
|
12
12
|
let(:body) { URI.encode_www_form(payload.to_a) }
|
13
|
-
let(:
|
13
|
+
let(:signature) { 'abc123' }
|
14
|
+
let(:headers) { { TxghServer::TransifexRequestAuth::RACK_HEADER => signature } }
|
15
|
+
let(:request) { TestRequest.new(body: body, headers: headers) }
|
14
16
|
let(:handler) { described_class.new(request, logger) }
|
15
17
|
let(:payload) { { 'project' => project_name, 'resource' => resource_slug, 'language' => 'pt' } }
|
16
18
|
|
17
19
|
describe '#handle_request' do
|
20
|
+
it 'publishes an event' do
|
21
|
+
expect { handler.handle_request }.to(
|
22
|
+
change { Txgh.events.published_in('transifex.webhook_received').size }.by(1)
|
23
|
+
)
|
24
|
+
|
25
|
+
event = Txgh.events.published_in('transifex.webhook_received').first
|
26
|
+
expect(event[:options][:payload]).to eq(Txgh::Utils.deep_symbolize_keys(payload))
|
27
|
+
expect(event[:options][:raw_payload]).to eq(body)
|
28
|
+
expect(event[:options][:signature]).to eq(signature)
|
29
|
+
end
|
30
|
+
|
18
31
|
it 'does not execute if unauthorized' do
|
19
32
|
expect_any_instance_of(Transifex::HookHandler).to_not receive(:execute)
|
20
33
|
response = handler.handle_request
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txgh-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Jackowski
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
174
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.6.13
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: An HTTP server for interacting with txgh.
|