3232import java .math .BigDecimal ;
3333import java .util .LinkedList ;
3434import java .util .List ;
35+ import java .util .Scanner ;
36+ import java .io .InputStream ;
3537
3638import static org .fest .assertions .api .Assertions .assertThat ;
3739import 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" )
0 commit comments