Skip to content

Commit 68b2b36

Browse files
committed
Merge pull request signalapp#8 from kyleconroy/opt_out_tests
Clean up tests. Add test for NOPAY in commit messages
2 parents e14894e + cdfbfa5 commit 68b2b36

File tree

6 files changed

+567
-4
lines changed

6 files changed

+567
-4
lines changed

src/test/java/org/whispersystems/bithub/tests/controllers/GithubControllerTest.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.math.BigDecimal;
3333
import java.util.LinkedList;
3434
import java.util.List;
35+
import java.util.Scanner;
36+
import java.io.InputStream;
3537

3638
import static org.fest.assertions.api.Assertions.assertThat;
3739
import static org.mockito.Matchers.*;
@@ -57,9 +59,15 @@ protected void setUpResources() throws Exception {
5759
addProvider(new UnauthorizedHookExceptionMapper());
5860
}
5961

62+
protected String payload(String path) {
63+
InputStream is = this.getClass().getResourceAsStream(path);
64+
Scanner s = new Scanner(is).useDelimiter("\\A");
65+
return s.hasNext() ? s.next() : "";
66+
}
67+
6068
@Test
6169
public void testInvalidRepository() throws Exception {
62-
String payloadValue = "{\"ref\":\"refs/heads/master\",\"after\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"before\":\"6626766348ab245bdb3351989f753bd6e792524a\",\"created\":false,\"deleted\":false,\"forced\":false,\"compare\":\"https://github.com/moxie0/tempt/compare/6626766348ab...100e9859651b\",\"commits\":[{\"id\":\"fd7daeb1de6d72220b1313a7f1112d43885013aa\",\"distinct\":true,\"message\":\"Update foo\",\"timestamp\":\"2013-12-14T11:27:00-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/fd7daeb1de6d72220b1313a7f1112d43885013aa\",\"author\":{\"name\":\"WhisperBTC\",\"email\":\"[email protected]\",\"username\":\"WhisperBTC\"},\"committer\":{\"name\":\"WhisperBTC\",\"email\":\"[email protected]\",\"username\":\"WhisperBTC\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]},{\"id\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"distinct\":true,\"message\":\"Merge pull request #2 from WhisperBTC/patch-2\\n\\nUpdate foo\",\"timestamp\":\"2013-12-14T11:27:28-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]}],\"head_commit\":{\"id\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"distinct\":true,\"message\":\"Merge pull request #2 from WhisperBTC/patch-2\\n\\nUpdate foo\",\"timestamp\":\"2013-12-14T11:27:28-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]},\"repository\":{\"id\":15141344,\"name\":\"tempt\",\"url\":\"https://github.com/moxie0/tempt\",\"description\":\"test\",\"watchers\":1,\"stargazers\":1,\"forks\":1,\"fork\":false,\"size\":216,\"owner\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"},\"private\":false,\"open_issues\":0,\"has_issues\":true,\"has_downloads\":true,\"has_wiki\":true,\"created_at\":1386866024,\"pushed_at\":1387049248,\"master_branch\":\"master\"},\"pusher\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"}}";
70+
String payloadValue = payload("/payloads/invalid_repo.json");
6371
MultivaluedMapImpl post = new MultivaluedMapImpl();
6472
post.add("payload", payloadValue);
6573
ClientResponse response = client().resource("/v1/github/commits/")
@@ -72,7 +80,7 @@ public void testInvalidRepository() throws Exception {
7280

7381
@Test
7482
public void testInvalidOrigin() throws Exception {
75-
String payloadValue = "{\"ref\":\"refs/heads/master\",\"after\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"before\":\"6626766348ab245bdb3351989f753bd6e792524a\",\"created\":false,\"deleted\":false,\"forced\":false,\"compare\":\"https://github.com/moxie0/tempt/compare/6626766348ab...100e9859651b\",\"commits\":[{\"id\":\"fd7daeb1de6d72220b1313a7f1112d43885013aa\",\"distinct\":true,\"message\":\"Update foo\",\"timestamp\":\"2013-12-14T11:27:00-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/fd7daeb1de6d72220b1313a7f1112d43885013aa\",\"author\":{\"name\":\"WhisperBTC\",\"email\":\"[email protected]\",\"username\":\"WhisperBTC\"},\"committer\":{\"name\":\"WhisperBTC\",\"email\":\"[email protected]\",\"username\":\"WhisperBTC\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]},{\"id\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"distinct\":true,\"message\":\"Merge pull request #2 from WhisperBTC/patch-2\\n\\nUpdate foo\",\"timestamp\":\"2013-12-14T11:27:28-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]}],\"head_commit\":{\"id\":\"100e9859651b35a3505cc278e9a98a076f79940b\",\"distinct\":true,\"message\":\"Merge pull request #2 from WhisperBTC/patch-2\\n\\nUpdate foo\",\"timestamp\":\"2013-12-14T11:27:28-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[\"foo\"]},\"repository\":{\"id\":15141344,\"name\":\"tempt\",\"url\":\"https://github.com/moxie0/test\",\"description\":\"test\",\"watchers\":1,\"stargazers\":1,\"forks\":1,\"fork\":false,\"size\":216,\"owner\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"},\"private\":false,\"open_issues\":0,\"has_issues\":true,\"has_downloads\":true,\"has_wiki\":true,\"created_at\":1386866024,\"pushed_at\":1387049248,\"master_branch\":\"master\"},\"pusher\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"}}";
83+
String payloadValue = payload("/payloads/invalid_origin.json");
7684
MultivaluedMapImpl post = new MultivaluedMapImpl();
7785
post.add("payload", payloadValue);
7886
ClientResponse response = client().resource("/v1/github/commits/")
@@ -83,9 +91,24 @@ public void testInvalidOrigin() throws Exception {
8391
assertThat(response.getStatus()).isEqualTo(401);
8492
}
8593

94+
@Test
95+
public void testOptOutCommit() throws Exception, TransferFailedException {
96+
String payloadValue = payload("/payloads/opt_out_commit.json");
97+
MultivaluedMapImpl post = new MultivaluedMapImpl();
98+
post.add("payload", payloadValue);
99+
ClientResponse response = client().resource("/v1/github/commits/")
100+
.header("X-Forwarded-For", "192.30.252.1")
101+
.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
102+
.post(ClientResponse.class, post);
103+
104+
verify(coinbaseClient, never()).sendPayment(any(Author.class),
105+
any(BigDecimal.class),
106+
anyString());
107+
}
108+
86109
@Test
87110
public void testValidCommit() throws Exception, TransferFailedException {
88-
String payloadValue = "{\"ref\":\"refs/heads/master\",\"after\":\"bcf09f8b4a32921114587e4814a3f0849aa9900f\",\"before\":\"1b141aa068165dd1ed376f483cd5fdc2c64f32b1\",\"created\":false,\"deleted\":false,\"forced\":false,\"compare\":\"https://github.com/moxie0/tempt/compare/1b141aa06816...bcf09f8b4a32\",\"commits\":[{\"id\":\"ba1b681c71db4fcd461954b1bf344bc6e29411e5\",\"distinct\":true,\"message\":\"Update path\",\"timestamp\":\"2013-12-14T11:42:28-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/ba1b681c71db4fcd461954b1bf344bc6e29411e5\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[\"README.md\"]},{\"id\":\"bcf09f8b4a32921114587e4814a3f0849aa9900f\",\"distinct\":true,\"message\":\"Merge branch 'master' of github.com:moxie0/tempt\",\"timestamp\":\"2013-12-14T11:42:44-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/bcf09f8b4a32921114587e4814a3f0849aa9900f\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[]}],\"head_commit\":{\"id\":\"bcf09f8b4a32921114587e4814a3f0849aa9900f\",\"distinct\":true,\"message\":\"Merge branch 'master' of github.com:moxie0/tempt\",\"timestamp\":\"2013-12-14T11:42:44-08:00\",\"url\":\"https://github.com/moxie0/tempt/commit/bcf09f8b4a32921114587e4814a3f0849aa9900f\",\"author\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"committer\":{\"name\":\"Moxie Marlinspike\",\"email\":\"[email protected]\",\"username\":\"moxie0\"},\"added\":[],\"removed\":[],\"modified\":[]},\"repository\":{\"id\":15141344,\"name\":\"tempt\",\"url\":\"https://github.com/moxie0/test\",\"description\":\"test\",\"watchers\":1,\"stargazers\":1,\"forks\":1,\"fork\":false,\"size\":216,\"owner\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"},\"private\":false,\"open_issues\":0,\"has_issues\":true,\"has_downloads\":true,\"has_wiki\":true,\"created_at\":1386866024,\"pushed_at\":1387050173,\"master_branch\":\"master\"},\"pusher\":{\"name\":\"moxie0\",\"email\":\"[email protected]\"}}";
111+
String payloadValue = payload("/payloads/valid_commit.json");
89112
MultivaluedMapImpl post = new MultivaluedMapImpl();
90113
post.add("payload", payloadValue);
91114
ClientResponse response = client().resource("/v1/github/commits/")
@@ -100,7 +123,7 @@ public void testValidCommit() throws Exception, TransferFailedException {
100123

101124
@Test
102125
public void testValidMultipleCommitsMultipleAuthors() throws Exception, TransferFailedException {
103-
String payloadValue = "{\"after\":\"1481a2de7b2a7d02428ad93446ab166be7793fbb\",\"before\":\"17c497ccc7cca9c2f735aa07e9e3813060ce9a6a\",\"commits\":[{\"added\":[],\"author\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"committer\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"distinct\":true,\"id\":\"c441029cf673f84c8b7db52d0a5944ee5c52ff89\",\"message\":\"Test\",\"modified\":[\"README.md\"],\"removed\":[],\"timestamp\":\"2013-02-22T13:50:07-08:00\",\"url\":\"https://github.com/octokitty/testing/commit/c441029cf673f84c8b7db52d0a5944ee5c52ff89\"},{\"added\":[],\"author\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"committer\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"distinct\":true,\"id\":\"36c5f2243ed24de58284a96f2a643bed8c028658\",\"message\":\"This is me testing the windows client.\",\"modified\":[\"README.md\"],\"removed\":[],\"timestamp\":\"2013-02-22T14:07:13-08:00\",\"url\":\"https://github.com/octokitty/testing/commit/36c5f2243ed24de58284a96f2a643bed8c028658\"},{\"added\":[\"words/madame-bovary.txt\"],\"author\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"committer\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"distinct\":true,\"id\":\"1481a2de7b2a7d02428ad93446ab166be7793fbb\",\"message\":\"Rename madame-bovary.txt to words/madame-bovary.txt\",\"modified\":[],\"removed\":[\"madame-bovary.txt\"],\"timestamp\":\"2013-03-12T08:14:29-07:00\",\"url\":\"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb\"}],\"compare\":\"https://github.com/octokitty/testing/compare/17c497ccc7cc...1481a2de7b2a\",\"created\":false,\"deleted\":false,\"forced\":false,\"head_commit\":{\"added\":[\"words/madame-bovary.txt\"],\"author\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"committer\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\",\"username\":\"octokitty\"},\"distinct\":true,\"id\":\"1481a2de7b2a7d02428ad93446ab166be7793fbb\",\"message\":\"Rename madame-bovary.txt to words/madame-bovary.txt\",\"modified\":[],\"removed\":[\"madame-bovary.txt\"],\"timestamp\":\"2013-03-12T08:14:29-07:00\",\"url\":\"https://github.com/octokitty/testing/commit/1481a2de7b2a7d02428ad93446ab166be7793fbb\"},\"pusher\":{\"email\":\"[email protected]\",\"name\":\"Garen Torikian\"},\"ref\":\"refs/heads/master\",\"repository\":{\"created_at\":1332977768,\"description\":\"\",\"fork\":false,\"forks\":0,\"has_downloads\":true,\"has_issues\":true,\"has_wiki\":true,\"homepage\":\"\",\"id\":3860742,\"language\":\"Ruby\",\"master_branch\":\"master\",\"name\":\"testing\",\"open_issues\":2,\"owner\":{\"email\":\"[email protected]\",\"name\":\"octokitty\"},\"private\":false,\"pushed_at\":1363295520,\"size\":2156,\"stargazers\":1,\"url\":\"https://github.com/moxie0/test\",\"watchers\":1}}";
126+
String payloadValue = payload("/payloads/multiple_commits_authors.json");
104127
MultivaluedMapImpl post = new MultivaluedMapImpl();
105128
post.add("payload", payloadValue);
106129
ClientResponse response = client().resource("/v1/github/commits/").header("X-Forwarded-For", "192.30.252.1")
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"after": "100e9859651b35a3505cc278e9a98a076f79940b",
3+
"before": "6626766348ab245bdb3351989f753bd6e792524a",
4+
"commits": [
5+
{
6+
"added": [],
7+
"author": {
8+
"email": "[email protected]",
9+
"name": "WhisperBTC",
10+
"username": "WhisperBTC"
11+
},
12+
"committer": {
13+
"email": "[email protected]",
14+
"name": "WhisperBTC",
15+
"username": "WhisperBTC"
16+
},
17+
"distinct": true,
18+
"id": "fd7daeb1de6d72220b1313a7f1112d43885013aa",
19+
"message": "Update foo",
20+
"modified": [
21+
"foo"
22+
],
23+
"removed": [],
24+
"timestamp": "2013-12-14T11:27:00-08:00",
25+
"url": "https://github.com/moxie0/tempt/commit/fd7daeb1de6d72220b1313a7f1112d43885013aa"
26+
},
27+
{
28+
"added": [],
29+
"author": {
30+
"email": "[email protected]",
31+
"name": "Moxie Marlinspike",
32+
"username": "moxie0"
33+
},
34+
"committer": {
35+
"email": "[email protected]",
36+
"name": "Moxie Marlinspike",
37+
"username": "moxie0"
38+
},
39+
"distinct": true,
40+
"id": "100e9859651b35a3505cc278e9a98a076f79940b",
41+
"message": "Merge pull request #2 from WhisperBTC/patch-2\n\nUpdate foo",
42+
"modified": [
43+
"foo"
44+
],
45+
"removed": [],
46+
"timestamp": "2013-12-14T11:27:28-08:00",
47+
"url": "https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b"
48+
}
49+
],
50+
"compare": "https://github.com/moxie0/tempt/compare/6626766348ab...100e9859651b",
51+
"created": false,
52+
"deleted": false,
53+
"forced": false,
54+
"head_commit": {
55+
"added": [],
56+
"author": {
57+
"email": "[email protected]",
58+
"name": "Moxie Marlinspike",
59+
"username": "moxie0"
60+
},
61+
"committer": {
62+
"email": "[email protected]",
63+
"name": "Moxie Marlinspike",
64+
"username": "moxie0"
65+
},
66+
"distinct": true,
67+
"id": "100e9859651b35a3505cc278e9a98a076f79940b",
68+
"message": "Merge pull request #2 from WhisperBTC/patch-2\n\nUpdate foo",
69+
"modified": [
70+
"foo"
71+
],
72+
"removed": [],
73+
"timestamp": "2013-12-14T11:27:28-08:00",
74+
"url": "https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b"
75+
},
76+
"pusher": {
77+
"email": "[email protected]",
78+
"name": "moxie0"
79+
},
80+
"ref": "refs/heads/master",
81+
"repository": {
82+
"created_at": 1386866024,
83+
"description": "test",
84+
"fork": false,
85+
"forks": 1,
86+
"has_downloads": true,
87+
"has_issues": true,
88+
"has_wiki": true,
89+
"id": 15141344,
90+
"master_branch": "master",
91+
"name": "tempt",
92+
"open_issues": 0,
93+
"owner": {
94+
"email": "[email protected]",
95+
"name": "moxie0"
96+
},
97+
"private": false,
98+
"pushed_at": 1387049248,
99+
"size": 216,
100+
"stargazers": 1,
101+
"url": "https://github.com/moxie0/test",
102+
"watchers": 1
103+
}
104+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"after": "100e9859651b35a3505cc278e9a98a076f79940b",
3+
"before": "6626766348ab245bdb3351989f753bd6e792524a",
4+
"commits": [
5+
{
6+
"added": [],
7+
"author": {
8+
"email": "[email protected]",
9+
"name": "WhisperBTC",
10+
"username": "WhisperBTC"
11+
},
12+
"committer": {
13+
"email": "[email protected]",
14+
"name": "WhisperBTC",
15+
"username": "WhisperBTC"
16+
},
17+
"distinct": true,
18+
"id": "fd7daeb1de6d72220b1313a7f1112d43885013aa",
19+
"message": "Update foo",
20+
"modified": [
21+
"foo"
22+
],
23+
"removed": [],
24+
"timestamp": "2013-12-14T11:27:00-08:00",
25+
"url": "https://github.com/moxie0/tempt/commit/fd7daeb1de6d72220b1313a7f1112d43885013aa"
26+
},
27+
{
28+
"added": [],
29+
"author": {
30+
"email": "[email protected]",
31+
"name": "Moxie Marlinspike",
32+
"username": "moxie0"
33+
},
34+
"committer": {
35+
"email": "[email protected]",
36+
"name": "Moxie Marlinspike",
37+
"username": "moxie0"
38+
},
39+
"distinct": true,
40+
"id": "100e9859651b35a3505cc278e9a98a076f79940b",
41+
"message": "Merge pull request #2 from WhisperBTC/patch-2\n\nUpdate foo",
42+
"modified": [
43+
"foo"
44+
],
45+
"removed": [],
46+
"timestamp": "2013-12-14T11:27:28-08:00",
47+
"url": "https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b"
48+
}
49+
],
50+
"compare": "https://github.com/moxie0/tempt/compare/6626766348ab...100e9859651b",
51+
"created": false,
52+
"deleted": false,
53+
"forced": false,
54+
"head_commit": {
55+
"added": [],
56+
"author": {
57+
"email": "[email protected]",
58+
"name": "Moxie Marlinspike",
59+
"username": "moxie0"
60+
},
61+
"committer": {
62+
"email": "[email protected]",
63+
"name": "Moxie Marlinspike",
64+
"username": "moxie0"
65+
},
66+
"distinct": true,
67+
"id": "100e9859651b35a3505cc278e9a98a076f79940b",
68+
"message": "Merge pull request #2 from WhisperBTC/patch-2\n\nUpdate foo",
69+
"modified": [
70+
"foo"
71+
],
72+
"removed": [],
73+
"timestamp": "2013-12-14T11:27:28-08:00",
74+
"url": "https://github.com/moxie0/tempt/commit/100e9859651b35a3505cc278e9a98a076f79940b"
75+
},
76+
"pusher": {
77+
"email": "[email protected]",
78+
"name": "moxie0"
79+
},
80+
"ref": "refs/heads/master",
81+
"repository": {
82+
"created_at": 1386866024,
83+
"description": "test",
84+
"fork": false,
85+
"forks": 1,
86+
"has_downloads": true,
87+
"has_issues": true,
88+
"has_wiki": true,
89+
"id": 15141344,
90+
"master_branch": "master",
91+
"name": "tempt",
92+
"open_issues": 0,
93+
"owner": {
94+
"email": "[email protected]",
95+
"name": "moxie0"
96+
},
97+
"private": false,
98+
"pushed_at": 1387049248,
99+
"size": 216,
100+
"stargazers": 1,
101+
"url": "https://github.com/moxie0/tempt",
102+
"watchers": 1
103+
}
104+
}

0 commit comments

Comments
 (0)