11package org .kohsuke .github ;
22
33import org .junit .Test ;
4+ import org .kohsuke .github .authorization .AppInstallationAuthorizationProvider ;
45import org .kohsuke .github .authorization .ImmutableAuthorizationProvider ;
56import org .kohsuke .github .authorization .OrgAppInstallationAuthorizationProvider ;
67
78import java .io .IOException ;
89
910import static org .hamcrest .CoreMatchers .equalTo ;
1011import static org .hamcrest .CoreMatchers .notNullValue ;
12+ import static org .hamcrest .CoreMatchers .startsWith ;
1113
1214// TODO: Auto-generated Javadoc
15+
1316/**
14- * The Class OrgAppInstallationAuthorizationProviderTest .
17+ * The Class AppInstallationAuthorizationProviderTest .
1518 */
16- public class OrgAppInstallationAuthorizationProviderTest extends AbstractGHAppInstallationTest {
19+ public class AppInstallationAuthorizationProviderTest extends AbstractGHAppInstallationTest {
1720
1821 /**
1922 * Instantiates a new org app installation authorization provider test.
2023 */
21- public OrgAppInstallationAuthorizationProviderTest () {
24+ public AppInstallationAuthorizationProviderTest () {
2225 useDefaultGitHub = false ;
2326 }
2427
@@ -48,7 +51,8 @@ public void invalidJWTTokenRaisesException() throws IOException {
4851 */
4952 @ Test
5053 public void validJWTTokenAllowsOauthTokenRequest () throws IOException {
51- OrgAppInstallationAuthorizationProvider provider = new OrgAppInstallationAuthorizationProvider ("hub4j-test-org" ,
54+ AppInstallationAuthorizationProvider provider = new AppInstallationAuthorizationProvider (
55+ app -> app .getInstallationByOrganization ("hub4j-test-org" ),
5256 ImmutableAuthorizationProvider .fromJwtToken ("bogus-valid-token" ));
5357 gitHub = getGitHubBuilder ().withAuthorizationProvider (provider )
5458 .withEndpoint (mockGitHub .apiServer ().baseUrl ())
@@ -59,4 +63,27 @@ public void validJWTTokenAllowsOauthTokenRequest() throws IOException {
5963 assertThat (encodedAuthorization , equalTo ("token v1.9a12d913f980a45a16ac9c3a9d34d9b7sa314cb6" ));
6064 }
6165
66+ /**
67+ * Lookup of an app by id works as expected
68+ *
69+ * @throws IOException
70+ * Signals that an I/O exception has occurred.
71+ */
72+ @ Test
73+ public void validJWTTokenWhenLookingUpAppById () throws IOException {
74+ AppInstallationAuthorizationProvider provider = new AppInstallationAuthorizationProvider (
75+ // https://github.com/organizations/hub4j-test-org/settings/installations/12129901
76+ app -> app .getInstallationById (12129901L ),
77+ jwtProvider1 );
78+ gitHub = getGitHubBuilder ().withAuthorizationProvider (provider )
79+ .withEndpoint (mockGitHub .apiServer ().baseUrl ())
80+ .build ();
81+ String encodedAuthorization = provider .getEncodedAuthorization ();
82+
83+ assertThat (encodedAuthorization , notNullValue ());
84+ // we could assert on the exact token with wiremock, but it would make the update of the test more complex
85+ // do we really care, getting a token should be enough.
86+ assertThat (encodedAuthorization , startsWith ("token ghs_" ));
87+ }
88+
6289}
0 commit comments