txgh-server 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/lib/txgh-server/application.rb +141 -0
  3. data/lib/txgh-server/download_handler.rb +85 -0
  4. data/lib/txgh-server/github_request_auth.rb +28 -0
  5. data/lib/txgh-server/response.rb +15 -0
  6. data/lib/txgh-server/response_helpers.rb +26 -0
  7. data/lib/txgh-server/stream_response.rb +37 -0
  8. data/lib/txgh-server/tgz_stream_response.rb +39 -0
  9. data/lib/txgh-server/transifex_request_auth.rb +53 -0
  10. data/lib/txgh-server/triggers/handler.rb +50 -0
  11. data/lib/txgh-server/triggers/pull_handler.rb +18 -0
  12. data/lib/txgh-server/triggers/push_handler.rb +18 -0
  13. data/lib/txgh-server/triggers.rb +7 -0
  14. data/lib/txgh-server/version.rb +3 -0
  15. data/lib/txgh-server/webhooks/github/delete_handler.rb +37 -0
  16. data/lib/txgh-server/webhooks/github/handler.rb +20 -0
  17. data/lib/txgh-server/webhooks/github/ping_handler.rb +18 -0
  18. data/lib/txgh-server/webhooks/github/push_handler.rb +124 -0
  19. data/lib/txgh-server/webhooks/github/request_handler.rb +113 -0
  20. data/lib/txgh-server/webhooks/github.rb +11 -0
  21. data/lib/txgh-server/webhooks/transifex/hook_handler.rb +94 -0
  22. data/lib/txgh-server/webhooks/transifex/request_handler.rb +78 -0
  23. data/lib/txgh-server/webhooks/transifex.rb +8 -0
  24. data/lib/txgh-server/webhooks.rb +6 -0
  25. data/lib/txgh-server/zip_stream_response.rb +19 -0
  26. data/lib/txgh-server.rb +23 -0
  27. data/spec/application_spec.rb +347 -0
  28. data/spec/download_handler_spec.rb +91 -0
  29. data/spec/github_request_auth_spec.rb +39 -0
  30. data/spec/helpers/github_payload_builder.rb +141 -0
  31. data/spec/helpers/integration_setup.rb +47 -0
  32. data/spec/integration/cassettes/github_l10n_hook_endpoint.yml +536 -0
  33. data/spec/integration/cassettes/pull.yml +47 -0
  34. data/spec/integration/cassettes/push.yml +544 -0
  35. data/spec/integration/cassettes/transifex_hook_endpoint.yml +221 -0
  36. data/spec/integration/config/tx.config +10 -0
  37. data/spec/integration/hooks_spec.rb +159 -0
  38. data/spec/integration/payloads/github_postbody.json +161 -0
  39. data/spec/integration/payloads/github_postbody_l10n.json +136 -0
  40. data/spec/integration/payloads/github_postbody_release.json +136 -0
  41. data/spec/integration/triggers_spec.rb +45 -0
  42. data/spec/spec_helper.rb +26 -0
  43. data/spec/tgz_stream_response_spec.rb +59 -0
  44. data/spec/transifex_request_auth_spec.rb +39 -0
  45. data/spec/webhooks/github/delete_handler_spec.rb +38 -0
  46. data/spec/webhooks/github/ping_handler_spec.rb +16 -0
  47. data/spec/webhooks/github/push_handler_spec.rb +106 -0
  48. data/spec/webhooks/transifex/hook_handler_spec.rb +136 -0
  49. data/spec/zip_stream_response_spec.rb +58 -0
  50. data/txgh-server.gemspec +24 -0
  51. metadata +170 -0
@@ -0,0 +1,136 @@
1
+ {
2
+ "ref": "refs/tags/L10N",
3
+ "before": "0000000000000000000000000000000000000000",
4
+ "after": "6eebc3eee49e8d46f6dbec16fe3360961bfdd8ed",
5
+ "created": true,
6
+ "deleted": false,
7
+ "forced": true,
8
+ "base_ref": "refs/heads/master",
9
+ "compare": "https://github.com/txgh-bot/txgh-test-resources/compare/L10N",
10
+ "commits": [
11
+
12
+ ],
13
+ "head_commit": {
14
+ "id": "6eebc3eee49e8d46f6dbec16fe3360961bfdd8ed",
15
+ "distinct": true,
16
+ "message": "10",
17
+ "timestamp": "2015-11-19T12:56:33-08:00",
18
+ "url": "https://github.com/txgh-bot/txgh-test-resources/commit/6eebc3eee49e8d46f6dbec16fe3360961bfdd8ed",
19
+ "author": {
20
+ "name": "Txgh Bot",
21
+ "email": "txgh.bot@gmail.com",
22
+ "username": "txgh-bot"
23
+ },
24
+ "committer": {
25
+ "name": "Txgh Bot",
26
+ "email": "txgh.bot@gmail.com",
27
+ "username": "txgh-bot"
28
+ },
29
+ "added": [
30
+
31
+ ],
32
+ "removed": [
33
+
34
+ ],
35
+ "modified": [
36
+ "sample.po"
37
+ ]
38
+ },
39
+ "repository": {
40
+ "id": 41740726,
41
+ "name": "txgh-test-resources",
42
+ "full_name": "txgh-bot/txgh-test-resources",
43
+ "owner": {
44
+ "name": "txgh-bot",
45
+ "email": "txgh.bot@gmail.com"
46
+ },
47
+ "private": false,
48
+ "html_url": "https://github.com/txgh-bot/txgh-test-resources",
49
+ "description": "Translation test repo for txgh",
50
+ "fork": false,
51
+ "url": "https://github.com/txgh-bot/txgh-test-resources",
52
+ "forks_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/forks",
53
+ "keys_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/keys{/key_id}",
54
+ "collaborators_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/collaborators{/collaborator}",
55
+ "teams_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/teams",
56
+ "hooks_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/hooks",
57
+ "issue_events_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues/events{/number}",
58
+ "events_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/events",
59
+ "assignees_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/assignees{/user}",
60
+ "branches_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/branches{/branch}",
61
+ "tags_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/tags",
62
+ "blobs_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/blobs{/sha}",
63
+ "git_tags_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/tags{/sha}",
64
+ "git_refs_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/refs{/sha}",
65
+ "trees_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/trees{/sha}",
66
+ "statuses_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/statuses/{sha}",
67
+ "languages_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/languages",
68
+ "stargazers_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/stargazers",
69
+ "contributors_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/contributors",
70
+ "subscribers_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/subscribers",
71
+ "subscription_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/subscription",
72
+ "commits_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/commits{/sha}",
73
+ "git_commits_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/commits{/sha}",
74
+ "comments_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/comments{/number}",
75
+ "issue_comment_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues/comments{/number}",
76
+ "contents_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/contents/{+path}",
77
+ "compare_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/compare/{base}...{head}",
78
+ "merges_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/merges",
79
+ "archive_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/{archive_format}{/ref}",
80
+ "downloads_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/downloads",
81
+ "issues_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues{/number}",
82
+ "pulls_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/pulls{/number}",
83
+ "milestones_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/milestones{/number}",
84
+ "notifications_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/notifications{?since,all,participating}",
85
+ "labels_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/labels{/name}",
86
+ "releases_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/releases{/id}",
87
+ "created_at": 1441114620,
88
+ "updated_at": "2015-09-01T13:37:00Z",
89
+ "pushed_at": 1447966674,
90
+ "git_url": "git://github.com/txgh-bot/txgh-test-resources.git",
91
+ "ssh_url": "git@github.com:txgh-bot/txgh-test-resources.git",
92
+ "clone_url": "https://github.com/txgh-bot/txgh-test-resources.git",
93
+ "svn_url": "https://github.com/txgh-bot/txgh-test-resources",
94
+ "homepage": null,
95
+ "size": 12,
96
+ "stargazers_count": 0,
97
+ "watchers_count": 0,
98
+ "language": null,
99
+ "has_issues": true,
100
+ "has_downloads": true,
101
+ "has_wiki": true,
102
+ "has_pages": false,
103
+ "forks_count": 0,
104
+ "mirror_url": null,
105
+ "open_issues_count": 0,
106
+ "forks": 0,
107
+ "open_issues": 0,
108
+ "watchers": 0,
109
+ "default_branch": "master",
110
+ "stargazers": 0,
111
+ "master_branch": "master"
112
+ },
113
+ "pusher": {
114
+ "name": "txgh-bot",
115
+ "email": "txgh.bot@gmail.com"
116
+ },
117
+ "sender": {
118
+ "login": "txgh-bot",
119
+ "id": 974299,
120
+ "avatar_url": "https://avatars.githubusercontent.com/u/974299?v=3",
121
+ "gravatar_id": "",
122
+ "url": "https://api.github.com/users/txgh-bot",
123
+ "html_url": "https://github.com/txgh-bot",
124
+ "followers_url": "https://api.github.com/users/txgh-bot/followers",
125
+ "following_url": "https://api.github.com/users/txgh-bot/following{/other_user}",
126
+ "gists_url": "https://api.github.com/users/txgh-bot/gists{/gist_id}",
127
+ "starred_url": "https://api.github.com/users/txgh-bot/starred{/owner}{/repo}",
128
+ "subscriptions_url": "https://api.github.com/users/txgh-bot/subscriptions",
129
+ "organizations_url": "https://api.github.com/users/txgh-bot/orgs",
130
+ "repos_url": "https://api.github.com/users/txgh-bot/repos",
131
+ "events_url": "https://api.github.com/users/txgh-bot/events{/privacy}",
132
+ "received_events_url": "https://api.github.com/users/txgh-bot/received_events",
133
+ "type": "User",
134
+ "site_admin": false
135
+ }
136
+ }
@@ -0,0 +1,136 @@
1
+ {
2
+ "ref": "refs/tags/v3.0.0",
3
+ "before": "0000000000000000000000000000000000000000",
4
+ "after": "a779a46381d0d10c8e9dc390da0eaf567465cb39",
5
+ "created": true,
6
+ "deleted": false,
7
+ "forced": true,
8
+ "base_ref": "refs/heads/master",
9
+ "compare": "https://github.com/txgh-bot/txgh-test-resources/compare/v3.0.0",
10
+ "commits": [
11
+
12
+ ],
13
+ "head_commit": {
14
+ "id": "a779a46381d0d10c8e9dc390da0eaf567465cb39",
15
+ "distinct": true,
16
+ "message": "11",
17
+ "timestamp": "2015-11-18T16:18:35-08:00",
18
+ "url": "https://github.com/txgh-bot/txgh-test-resources/commit/a779a46381d0d10c8e9dc390da0eaf567465cb39",
19
+ "author": {
20
+ "name": "Txgh Bot",
21
+ "email": "txgh.bot@gmail.com",
22
+ "username": "txgh-bot"
23
+ },
24
+ "committer": {
25
+ "name": "Txgh Bot",
26
+ "email": "txgh.bot@gmail.com",
27
+ "username": "txgh-bot"
28
+ },
29
+ "added": [
30
+
31
+ ],
32
+ "removed": [
33
+
34
+ ],
35
+ "modified": [
36
+ "sample.po"
37
+ ]
38
+ },
39
+ "repository": {
40
+ "id": 41740726,
41
+ "name": "txgh-test-resources",
42
+ "full_name": "txgh-bot/txgh-test-resources",
43
+ "owner": {
44
+ "name": "txgh-bot",
45
+ "email": "txgh.bot@gmail.com"
46
+ },
47
+ "private": false,
48
+ "html_url": "https://github.com/txgh-bot/txgh-test-resources",
49
+ "description": "Translation test repo for txgh",
50
+ "fork": false,
51
+ "url": "https://github.com/txgh-bot/txgh-test-resources",
52
+ "forks_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/forks",
53
+ "keys_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/keys{/key_id}",
54
+ "collaborators_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/collaborators{/collaborator}",
55
+ "teams_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/teams",
56
+ "hooks_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/hooks",
57
+ "issue_events_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues/events{/number}",
58
+ "events_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/events",
59
+ "assignees_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/assignees{/user}",
60
+ "branches_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/branches{/branch}",
61
+ "tags_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/tags",
62
+ "blobs_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/blobs{/sha}",
63
+ "git_tags_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/tags{/sha}",
64
+ "git_refs_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/refs{/sha}",
65
+ "trees_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/trees{/sha}",
66
+ "statuses_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/statuses/{sha}",
67
+ "languages_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/languages",
68
+ "stargazers_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/stargazers",
69
+ "contributors_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/contributors",
70
+ "subscribers_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/subscribers",
71
+ "subscription_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/subscription",
72
+ "commits_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/commits{/sha}",
73
+ "git_commits_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/git/commits{/sha}",
74
+ "comments_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/comments{/number}",
75
+ "issue_comment_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues/comments{/number}",
76
+ "contents_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/contents/{+path}",
77
+ "compare_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/compare/{base}...{head}",
78
+ "merges_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/merges",
79
+ "archive_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/{archive_format}{/ref}",
80
+ "downloads_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/downloads",
81
+ "issues_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/issues{/number}",
82
+ "pulls_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/pulls{/number}",
83
+ "milestones_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/milestones{/number}",
84
+ "notifications_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/notifications{?since,all,participating}",
85
+ "labels_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/labels{/name}",
86
+ "releases_url": "https://api.github.com/repos/txgh-bot/txgh-test-resources/releases{/id}",
87
+ "created_at": 1441114620,
88
+ "updated_at": "2015-09-01T13:37:00Z",
89
+ "pushed_at": 1447892352,
90
+ "git_url": "git://github.com/txgh-bot/txgh-test-resources.git",
91
+ "ssh_url": "git@github.com:txgh-bot/txgh-test-resources.git",
92
+ "clone_url": "https://github.com/txgh-bot/txgh-test-resources.git",
93
+ "svn_url": "https://github.com/txgh-bot/txgh-test-resources",
94
+ "homepage": null,
95
+ "size": 11,
96
+ "stargazers_count": 0,
97
+ "watchers_count": 0,
98
+ "language": null,
99
+ "has_issues": true,
100
+ "has_downloads": true,
101
+ "has_wiki": true,
102
+ "has_pages": false,
103
+ "forks_count": 0,
104
+ "mirror_url": null,
105
+ "open_issues_count": 0,
106
+ "forks": 0,
107
+ "open_issues": 0,
108
+ "watchers": 0,
109
+ "default_branch": "master",
110
+ "stargazers": 0,
111
+ "master_branch": "master"
112
+ },
113
+ "pusher": {
114
+ "name": "txgh-bot",
115
+ "email": "txgh.bot@gmail.com"
116
+ },
117
+ "sender": {
118
+ "login": "txgh-bot",
119
+ "id": 974299,
120
+ "avatar_url": "https://avatars.githubusercontent.com/u/974299?v=3",
121
+ "gravatar_id": "",
122
+ "url": "https://api.github.com/users/txgh-bot",
123
+ "html_url": "https://github.com/txgh-bot",
124
+ "followers_url": "https://api.github.com/users/txgh-bot/followers",
125
+ "following_url": "https://api.github.com/users/txgh-bot/following{/other_user}",
126
+ "gists_url": "https://api.github.com/users/txgh-bot/gists{/gist_id}",
127
+ "starred_url": "https://api.github.com/users/txgh-bot/starred{/owner}{/repo}",
128
+ "subscriptions_url": "https://api.github.com/users/txgh-bot/subscriptions",
129
+ "organizations_url": "https://api.github.com/users/txgh-bot/orgs",
130
+ "repos_url": "https://api.github.com/users/txgh-bot/repos",
131
+ "events_url": "https://api.github.com/users/txgh-bot/events{/privacy}",
132
+ "received_events_url": "https://api.github.com/users/txgh-bot/received_events",
133
+ "type": "User",
134
+ "site_admin": false
135
+ }
136
+ }
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ require 'rack/test'
4
+ require 'helpers/integration_setup'
5
+
6
+ describe 'trigger integration tests', integration: true do
7
+ include Rack::Test::Methods
8
+ include IntegrationSetup
9
+
10
+ def app
11
+ @app ||= TxghServer::TriggerEndpoints.new
12
+ end
13
+
14
+ around(:each) do |example|
15
+ Dir.chdir('./spec/integration') do
16
+ example.run
17
+ end
18
+ end
19
+
20
+ it 'verifies the pull endpoint works' do
21
+ VCR.use_cassette('pull') do
22
+ params = {
23
+ project_slug: 'test-project-88',
24
+ resource_slug: 'samplepo',
25
+ branch: 'master'
26
+ }
27
+
28
+ patch '/pull', params
29
+ expect(last_response).to be_ok
30
+ end
31
+ end
32
+
33
+ it 'verifies the push endpoint works' do
34
+ VCR.use_cassette('push') do
35
+ params = {
36
+ project_slug: 'test-project-88',
37
+ resource_slug: 'samplepo',
38
+ branch: 'master'
39
+ }
40
+
41
+ patch '/push', params
42
+ expect(last_response).to be_ok
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,26 @@
1
+ $:.push(File.join(Gem.loaded_specs['txgh'].full_gem_path, 'spec'))
2
+
3
+ require 'pry-byebug'
4
+ require 'rake'
5
+ require 'rspec'
6
+ require 'txgh-server'
7
+ require 'vcr'
8
+ require 'webmock'
9
+ require 'yaml'
10
+
11
+ require 'helpers/test_events'
12
+
13
+ RSpec.configure do |config|
14
+ config.filter_run(focus: true)
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run_excluding(integration: true) unless ENV['FULL_SPEC']
17
+
18
+ config.before(:each) do
19
+ Txgh.instance_variable_set(:@events, TestEvents.new)
20
+ end
21
+ end
22
+
23
+ VCR.configure do |config|
24
+ config.cassette_library_dir = 'spec/integration/cassettes'
25
+ config.hook_into :webmock
26
+ end
@@ -0,0 +1,59 @@
1
+ require 'rubygems/package'
2
+ require 'spec_helper'
3
+ require 'stringio'
4
+ require 'zlib'
5
+
6
+ include TxghServer
7
+
8
+ describe TgzStreamResponse do
9
+ def read_tgz_from(io)
10
+ contents = {}
11
+
12
+ Zlib::GzipReader.wrap(io) do |gz|
13
+ tar = Gem::Package::TarReader.new(gz)
14
+ tar.each do |entry|
15
+ contents[entry.full_name] = entry.read
16
+ end
17
+ end
18
+
19
+ contents
20
+ end
21
+
22
+ let(:attachment) { 'abc123' }
23
+
24
+ let(:enum) do
25
+ {
26
+ 'first_file.yml' => "first\nfile\ncontents\n",
27
+ 'second_file.yml' => "wowowow\nanother file!\n"
28
+ }
29
+ end
30
+
31
+ let(:response) do
32
+ TgzStreamResponse.new(attachment, enum)
33
+ end
34
+
35
+ describe '#write_to' do
36
+ it 'writes a gzipped tar file with the correct entries to the stream' do
37
+ io = StringIO.new('', 'wb')
38
+ response.write_to(io)
39
+ io = io.reopen(io.string, 'rb')
40
+ contents = read_tgz_from(io)
41
+ expect(contents).to eq(enum)
42
+ end
43
+ end
44
+
45
+ describe '#headers' do
46
+ it 'includes the correct content type and disposition headers' do
47
+ expect(response.headers).to eq({
48
+ 'Content-Disposition' => "attachment; filename=\"#{attachment}.tgz\"",
49
+ 'Content-Type' => 'application/x-gtar'
50
+ })
51
+ end
52
+ end
53
+
54
+ describe '#streaming?' do
55
+ it 'returns true' do
56
+ expect(response).to be_streaming
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'rack'
3
+
4
+ include TxghServer
5
+
6
+ describe TransifexRequestAuth do
7
+ let(:secret) { 'abc123' }
8
+ let(:params) { 'param1=value1&param2=value2&param3=123' }
9
+ let(:valid_signature) { 'pXucIcivBezpfNgCGTHKYeDve84=' }
10
+
11
+ describe '.authentic_request?' do
12
+ it 'returns true if the request is signed correctly' do
13
+ request = Rack::Request.new(
14
+ TransifexRequestAuth::RACK_HEADER => valid_signature,
15
+ 'rack.input' => StringIO.new(params)
16
+ )
17
+
18
+ authentic = TransifexRequestAuth.authentic_request?(request, secret)
19
+ expect(authentic).to eq(true)
20
+ end
21
+
22
+ it 'returns false if the request is not signed correctly' do
23
+ request = Rack::Request.new(
24
+ TransifexRequestAuth::RACK_HEADER => 'incorrect',
25
+ 'rack.input' => StringIO.new(params)
26
+ )
27
+
28
+ authentic = TransifexRequestAuth.authentic_request?(request, secret)
29
+ expect(authentic).to eq(false)
30
+ end
31
+ end
32
+
33
+ describe '.header' do
34
+ it 'calculates the signature and formats it as an http header' do
35
+ value = TransifexRequestAuth.header_value(params, secret)
36
+ expect(value).to eq(valid_signature)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'helpers/github_payload_builder'
3
+ require 'helpers/standard_txgh_setup'
4
+
5
+ include TxghServer
6
+ include TxghServer::Webhooks::Github
7
+
8
+ describe DeleteHandler do
9
+ include StandardTxghSetup
10
+
11
+ let(:handler) do
12
+ DeleteHandler.new(
13
+ project: transifex_project,
14
+ repo: github_repo,
15
+ payload: payload.to_h,
16
+ logger: logger
17
+ )
18
+ end
19
+
20
+ let(:payload) do
21
+ GithubPayloadBuilder.delete_payload(repo_name, ref)
22
+ end
23
+
24
+ it 'deletes resources' do
25
+ expect_any_instance_of(Txgh::ResourceDeleter).to receive(:delete_resources)
26
+ response = handler.execute
27
+ expect(response.status).to eq(200)
28
+ expect(response.body).to eq(true)
29
+ end
30
+
31
+ it 'does not delete resources if auto resource deletions are disabled' do
32
+ project_config['auto_delete_resources'] = 'false'
33
+ expect(transifex_api).to_not receive(:delete)
34
+ response = handler.execute
35
+ expect(response.status).to eq(200)
36
+ expect(response.body).to eq(true)
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ include TxghServer
4
+ include TxghServer::Webhooks::Github
5
+
6
+ describe PingHandler do
7
+ let(:handler) do
8
+ PingHandler.new
9
+ end
10
+
11
+ it 'responds with a 200 success' do
12
+ response = handler.execute
13
+ expect(response.status).to eq(200)
14
+ expect(response.body).to eq({})
15
+ end
16
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+ require 'helpers/github_payload_builder'
3
+ require 'helpers/standard_txgh_setup'
4
+
5
+ include TxghServer
6
+ include TxghServer::Webhooks::Github
7
+
8
+ describe PushHandler do
9
+ include StandardTxghSetup
10
+
11
+ let(:handler) do
12
+ PushHandler.new(
13
+ project: transifex_project,
14
+ repo: github_repo,
15
+ payload: payload.to_h,
16
+ logger: logger
17
+ )
18
+ end
19
+
20
+ let(:payload) do
21
+ GithubPayloadBuilder.push_payload(repo_name, ref)
22
+ end
23
+
24
+ let(:modified_files) do
25
+ file_sha = 'def456'
26
+ tx_config.resources.map do |resource|
27
+ { 'path' => resource.source_file, 'sha' => file_sha.next! }
28
+ end
29
+ end
30
+
31
+ let(:updater) { double(:updater) }
32
+
33
+ before(:each) do
34
+ payload.add_commit(
35
+ modified: modified_files.map { |f| f['path'] }
36
+ )
37
+
38
+ allow(Txgh::ResourceUpdater).to receive(:new).and_return(updater)
39
+ end
40
+
41
+ it 'correctly uploads modified resources to transifex' do
42
+ tx_config.resources.each do |resource|
43
+ expect(updater).to(
44
+ receive(:update_resource) do |resource, sha, categories|
45
+ expect(resource.project_slug).to eq(project_name)
46
+ expect(resource.resource_slug).to eq(resource_slug)
47
+ expect(sha).to eq(payload.head_commit[:id])
48
+ expect(categories).to eq('author' => 'Test User')
49
+ end
50
+ )
51
+
52
+ expect(github_api).to(
53
+ receive(:get_ref).with(repo_name, ref).and_return(
54
+ object: { sha: payload.head_commit[:id] }
55
+ )
56
+ )
57
+ end
58
+
59
+ response = handler.execute
60
+ expect(response.status).to eq(200)
61
+ expect(response.body).to eq(true)
62
+ end
63
+
64
+ context 'with an L10N branch' do
65
+ let(:ref) { 'tags/L10N_my_branch' }
66
+
67
+ it 'creates an L10N tag' do
68
+ expect(updater).to receive(:update_resource)
69
+
70
+ # this is what we actually care about in this test
71
+ expect(github_api).to(
72
+ receive(:create_ref).with(
73
+ repo_name, 'heads/L10N', payload.head_commit[:id]
74
+ )
75
+ )
76
+
77
+ expect(github_api).to(
78
+ receive(:get_ref).with(repo_name, ref).and_return(
79
+ object: { sha: payload.head_commit[:id] }
80
+ )
81
+ )
82
+
83
+ response = handler.execute
84
+ expect(response.status).to eq(200)
85
+ expect(response.body).to eq(true)
86
+ end
87
+ end
88
+
89
+ context 'with a deleted branch' do
90
+ let(:before) { nil }
91
+ let(:after) { '0' * 40 }
92
+
93
+ let(:payload) do
94
+ GithubPayloadBuilder.push_payload(repo_name, ref, before, after)
95
+ end
96
+
97
+ it "doesn't upload anything" do
98
+ expect(updater).to_not receive(:update_resource)
99
+ expect(github_api).to_not receive(:create_ref)
100
+
101
+ response = handler.execute
102
+ expect(response.status).to eq(200)
103
+ expect(response.body).to eq(true)
104
+ end
105
+ end
106
+ end