Added test for GitHub OAuth Plugin (#123)

This commit is contained in:
Mads Nielsen 2018-02-23 10:44:00 +01:00 committed by Ewelina Wilkosz
parent 7bb962a687
commit 81c0f79e4c
4 changed files with 76 additions and 0 deletions

View File

@ -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
View File

@ -182,6 +182,20 @@
<scope>test</scope>
</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 -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>

View File

@ -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());
}
}

View File

@ -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"