Skip to content

Commit 12c3a0b

Browse files
author
Alex Taylor
committed
Authentication and assertThat issues
Fixed some problems with tests trying to authenticate when you are not actually signed in. This hit rate API limiting which caused tests to hang/fail Also fixed assertThat getting deprecated from junit
1 parent a9bb930 commit 12c3a0b

30 files changed

Lines changed: 129 additions & 10 deletions

src/test/java/org/kohsuke/github/AbstractGitHubWireMockTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
44
import org.apache.commons.io.IOUtils;
55
import org.junit.After;
6-
import org.junit.Assert;
76
import org.junit.Before;
87
import org.junit.Rule;
98
import org.kohsuke.github.junit.GitHubWireMockRule;
@@ -13,13 +12,15 @@
1312
import java.io.IOException;
1413
import java.util.*;
1514

15+
import static org.hamcrest.MatcherAssert.assertThat;
16+
import static org.hamcrest.Matchers.is;
1617
import static org.junit.Assume.assumeFalse;
1718
import static org.junit.Assume.assumeTrue;
1819

1920
/**
2021
* @author Liam Newman
2122
*/
22-
public abstract class AbstractGitHubWireMockTest extends Assert {
23+
public abstract class AbstractGitHubWireMockTest {
2324

2425
private final GitHubBuilder githubBuilder = createGitHubBuilder();
2526

@@ -126,6 +127,13 @@ protected void requireProxy(String reason) {
126127
mockGitHub.isUseProxy());
127128
}
128129

130+
protected void verifyAuthenticated() {
131+
assertThat(
132+
"GitHub connection believes it is anonymous. Make sure you set GITHUB_OAUTH or both GITHUB_USER and GITHUB_PASSWORD environment variables",
133+
gitHub.isAnonymous(),
134+
is(false));
135+
}
136+
129137
protected GHUser getUser() {
130138
return getUser(gitHub);
131139
}
@@ -163,6 +171,10 @@ protected GHRepository getTempRepository() throws IOException {
163171
protected GHRepository getTempRepository(String name) throws IOException {
164172
String fullName = GITHUB_API_TEST_ORG + '/' + name;
165173
if (mockGitHub.isUseProxy()) {
174+
175+
// Needs to check if you are authenticated before doing this cleanup and repo creation
176+
verifyAuthenticated();
177+
166178
cleanupRepository(fullName);
167179

168180
GHRepository repository = gitHubBeforeAfter.getOrganization(GITHUB_API_TEST_ORG)

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,15 @@
1717
import java.util.regex.Pattern;
1818

1919
import static org.hamcrest.CoreMatchers.*;
20+
import static org.hamcrest.MatcherAssert.assertThat;
2021
import static org.hamcrest.Matchers.contains;
2122
import static org.hamcrest.Matchers.hasProperty;
23+
import static org.junit.Assert.assertEquals;
24+
import static org.junit.Assert.assertFalse;
25+
import static org.junit.Assert.assertNotNull;
26+
import static org.junit.Assert.assertSame;
27+
import static org.junit.Assert.assertTrue;
28+
import static org.junit.Assert.fail;
2229

2330
/**
2431
* Unit test for simple App.

src/test/java/org/kohsuke/github/CommitTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import java.io.IOException;
77

8+
import static org.hamcrest.CoreMatchers.*;
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertNotNull;
11+
812
/**
913
* @author Kohsuke Kawaguchi
1014
*/

src/test/java/org/kohsuke/github/GHAppTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12+
import static org.hamcrest.MatcherAssert.assertThat;
1213
import static org.hamcrest.Matchers.*;
14+
import static org.junit.Assert.assertNull;
15+
import static org.junit.Assert.fail;
1316

1417
/**
1518
* Tests for the GitHub App API methods

src/test/java/org/kohsuke/github/GHBranchProtectionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
import org.kohsuke.github.GHBranchProtection.RequiredReviews;
77
import org.kohsuke.github.GHBranchProtection.RequiredStatusChecks;
88

9+
import static org.hamcrest.Matchers.*;
10+
import static org.hamcrest.Matchers.contains;
11+
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertNotNull;
14+
import static org.junit.Assert.assertTrue;
15+
916
public class GHBranchProtectionTest extends AbstractGitHubWireMockTest {
1017
private static final String BRANCH = "master";
1118
private static final String BRANCH_REF = "heads/" + BRANCH;

src/test/java/org/kohsuke/github/GHContentIntegrationTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
import java.util.List;
1111

1212
import static org.hamcrest.CoreMatchers.*;
13+
import static org.hamcrest.MatcherAssert.assertThat;
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotNull;
16+
import static org.junit.Assert.assertNull;
17+
import static org.junit.Assert.assertTrue;
18+
import static org.junit.Assert.fail;
1319

1420
/**
1521
* Integration test for {@link GHContent}.

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import static org.hamcrest.CoreMatchers.is;
77
import static org.hamcrest.CoreMatchers.nullValue;
8-
import static org.junit.Assert.assertThat;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
import static org.hamcrest.Matchers.*;
910

1011
public class GHEventPayloadTest {
1112

src/test/java/org/kohsuke/github/GHGistTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
import org.junit.Test;
44

55
import static com.github.tomakehurst.wiremock.client.WireMock.*;
6+
import static org.hamcrest.MatcherAssert.assertThat;
7+
import static org.hamcrest.Matchers.*;
8+
import static org.hamcrest.Matchers.contains;
69
import static org.hamcrest.Matchers.notNullValue;
710
import static org.hamcrest.core.Is.is;
11+
import static org.junit.Assert.assertEquals;
12+
import static org.junit.Assert.assertFalse;
13+
import static org.junit.Assert.assertNotNull;
14+
import static org.junit.Assert.assertTrue;
15+
import static org.junit.Assert.fail;
816

917
/**
1018
* @author Kohsuke Kawaguchi

src/test/java/org/kohsuke/github/GHIssueEventTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import java.io.IOException;
66
import java.util.List;
77

8+
import static org.junit.Assert.assertEquals;
9+
import static org.junit.Assert.assertNotNull;
10+
import static org.junit.Assert.assertTrue;
11+
812
/**
913
* @author Martin van Zijl
1014
*/

src/test/java/org/kohsuke/github/GHLicenseTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
import java.io.IOException;
3131
import java.net.URL;
3232

33+
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertNull;
35+
import static org.junit.Assert.assertTrue;
36+
import static org.junit.Assert.fail;
37+
3338
/**
3439
* @author Duncan Dickinson
3540
*/

0 commit comments

Comments
 (0)