Added test for GitHub OAuth Plugin (#123)
This commit is contained in:
parent
7bb962a687
commit
81c0f79e4c
|
|
@ -0,0 +1,16 @@
|
||||||
|
# github-oauth-plugin
|
||||||
|
|
||||||
|
[Link to the plugin site](https://plugins.jenkins.io/github-oauth)
|
||||||
|
|
||||||
|
## sample-configuration
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jenkins:
|
||||||
|
securityRealm:
|
||||||
|
github:
|
||||||
|
githubWebUri: "https://github.com"
|
||||||
|
githubApiUri: "https://api.github.com"
|
||||||
|
clientID: "someId"
|
||||||
|
clientSecret: "${GITHUB_SECRET}"
|
||||||
|
oauthScopes: "read:org,user:email"
|
||||||
|
```
|
||||||
14
pom.xml
14
pom.xml
|
|
@ -181,6 +181,20 @@
|
||||||
<version>2.9</version>
|
<version>2.9</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jenkins-ci.plugins</groupId>
|
||||||
|
<artifactId>github-oauth</artifactId>
|
||||||
|
<version>0.29</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<!-- Provided by the Git plugin -->
|
||||||
|
<groupId>org.jenkins-ci.plugins</groupId>
|
||||||
|
<artifactId>matrix-project</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- required to satisfy plugins dependencies and get testPluginActive to pass -->
|
<!-- required to satisfy plugins dependencies and get testPluginActive to pass -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
package org.jenkinsci.plugins.casc;
|
||||||
|
|
||||||
|
import hudson.security.SecurityRealm;
|
||||||
|
import jenkins.model.Jenkins;
|
||||||
|
import org.jenkinsci.plugins.GithubSecurityRealm;
|
||||||
|
import org.jenkinsci.plugins.casc.misc.ConfiguredWithCode;
|
||||||
|
import org.jenkinsci.plugins.casc.misc.EnvVarsRule;
|
||||||
|
import org.jenkinsci.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.RuleChain;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purpose:
|
||||||
|
* Test that we can configure: <a href="https://plugins.jenkins.io/github-oauth"/>
|
||||||
|
*/
|
||||||
|
public class GithubOAuthTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public RuleChain rc = RuleChain.outerRule(new EnvVarsRule().env("GITHUB_SECRET","j985j8fhfhh377"))
|
||||||
|
.around(new JenkinsConfiguredWithCodeRule());
|
||||||
|
@Test
|
||||||
|
@ConfiguredWithCode("GithubOAuth.yml")
|
||||||
|
public void testSampleVersionForOAuth() {
|
||||||
|
SecurityRealm realm = Jenkins.getInstance().getSecurityRealm();
|
||||||
|
assertThat(realm, instanceOf(GithubSecurityRealm.class));
|
||||||
|
GithubSecurityRealm gsh = (GithubSecurityRealm)realm;
|
||||||
|
assertEquals("someId", gsh.getClientID());
|
||||||
|
assertEquals("https://api.github.com", gsh.getGithubApiUri());
|
||||||
|
assertEquals("https://github.com", gsh.getGithubWebUri());
|
||||||
|
assertEquals("j985j8fhfhh377", gsh.getClientSecret().getPlainText());
|
||||||
|
assertEquals("read:org,user:email", gsh.getOauthScopes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
jenkins:
|
||||||
|
securityRealm:
|
||||||
|
github:
|
||||||
|
githubWebUri: "https://github.com"
|
||||||
|
githubApiUri: "https://api.github.com"
|
||||||
|
clientID: "someId"
|
||||||
|
clientSecret: "${GITHUB_SECRET}"
|
||||||
|
oauthScopes: "read:org,user:email"
|
||||||
Loading…
Reference in New Issue