diff --git a/LICENSE.txt b/LICENSE.txt index d8fb0e73..7f4581ca 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -2,6 +2,7 @@ The MIT License Copyright (c) 2011 Michael O'Cleirigh Copyright (c) 2013-2014 Sam Kottler +Copyright (c) 2015 Sam Gleske Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java b/src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java index af8b679a..3085020b 100644 --- a/src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java +++ b/src/main/java/org/jenkinsci/plugins/GithubAuthorizationStrategy.java @@ -122,11 +122,11 @@ public ACL getRootACL() { public ACL getACL(Job job) { if(job instanceof AbstractProject) { AbstractProject project = (AbstractProject)job; - GithubRequireOrganizationMembershipACL githubACL = (GithubRequireOrganizationMembershipACL) getRootACL(); + GithubRequireOrganizationMembershipACL githubACL = (GithubRequireOrganizationMembershipACL) getRootACL(); return githubACL.cloneForProject(project); - } else { + } else { return getRootACL(); - } + } } /* @@ -216,6 +216,29 @@ public boolean isAllowAnonymousJobStatusPermission() { return rootACL.isAllowAnonymousJobStatusPermission(); } + /** + * Compare an object against this instance for equivalence. + * @param object An object to campare this instance to. + * @return true if the objects are the same instance and configuration. + */ + @Override + public boolean equals(Object object){ + if(object instanceof GithubAuthorizationStrategy) { + GithubAuthorizationStrategy obj = (GithubAuthorizationStrategy) object; + return this.getOrganizationNames().equals(obj.getOrganizationNames()) && + this.getAdminUserNames().equals(obj.getAdminUserNames()) && + this.isUseRepositoryPermissions() == obj.isUseRepositoryPermissions() && + this.isAuthenticatedUserCreateJobPermission() == obj.isAuthenticatedUserCreateJobPermission() && + this.isAuthenticatedUserReadPermission() == obj.isAuthenticatedUserReadPermission() && + this.isAllowGithubWebHookPermission() == obj.isAllowGithubWebHookPermission() && + this.isAllowCcTrayPermission() == obj.isAllowCcTrayPermission() && + this.isAllowAnonymousReadPermission() == obj.isAllowAnonymousReadPermission() && + this.isAllowAnonymousJobStatusPermission() == obj.isAllowAnonymousJobStatusPermission(); + } else { + return false; + } + } + @Extension public static final class DescriptorImpl extends Descriptor { diff --git a/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java b/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java index 356c1c8f..8a96c1ff 100644 --- a/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java +++ b/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java @@ -623,6 +623,25 @@ public UserDetails loadUserByUsername(String username) } } + /** + * Compare an object against this instance for equivalence. + * @param object An object to campare this instance to. + * @return true if the objects are the same instance and configuration. + */ + @Override + public boolean equals(Object object){ + if(object instanceof GithubSecurityRealm) { + GithubSecurityRealm obj = (GithubSecurityRealm) object; + return this.getGithubWebUri().equals(obj.getGithubWebUri()) && + this.getGithubApiUri().equals(obj.getGithubApiUri()) && + this.getClientID().equals(obj.getClientID()) && + this.getClientSecret().equals(obj.getClientSecret()) && + this.getOauthScopes().equals(obj.getOauthScopes()); + } else { + return false; + } + } + /** * * @param groupName diff --git a/src/test/java/org/jenkinsci/plugins/GithubAuthorizationStrategyTest.java b/src/test/java/org/jenkinsci/plugins/GithubAuthorizationStrategyTest.java new file mode 100644 index 00000000..44563865 --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/GithubAuthorizationStrategyTest.java @@ -0,0 +1,46 @@ +/** + The MIT License + +Copyright (c) 2015 Sam Gleske + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + */ + +package org.jenkinsci.plugins; + +import java.io.IOException; +import junit.framework.TestCase; +import org.junit.runner.RunWith; +import org.junit.Test; + +public class GithubAuthorizationStrategyTest extends TestCase { + @Test + public void testEquals_true() { + GithubAuthorizationStrategy a = new GithubAuthorizationStrategy(new String(""), false, true, false, new String(""), false, false, false, false); + GithubAuthorizationStrategy b = new GithubAuthorizationStrategy(new String(""), false, true, false, new String(""), false, false, false, false); + assertTrue(a.equals(b)); + } + @Test + public void testEquals_false() { + GithubAuthorizationStrategy a = new GithubAuthorizationStrategy(new String(""), false, true, false, new String(""), false, false, false, false); + GithubAuthorizationStrategy b = new GithubAuthorizationStrategy(new String(""), false, false, false, new String(""), false, false, false, false); + assertFalse(a.equals(b)); + assertFalse(a.equals("")); + } +} diff --git a/src/test/java/org/jenkinsci/plugins/GithubSecurityRealmTest.java b/src/test/java/org/jenkinsci/plugins/GithubSecurityRealmTest.java new file mode 100644 index 00000000..ee1b04ca --- /dev/null +++ b/src/test/java/org/jenkinsci/plugins/GithubSecurityRealmTest.java @@ -0,0 +1,46 @@ +/** + The MIT License + +Copyright (c) 2015 Sam Gleske + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + */ + +package org.jenkinsci.plugins; + +import java.io.IOException; +import junit.framework.TestCase; +import org.junit.runner.RunWith; +import org.junit.Test; + +public class GithubSecurityRealmTest extends TestCase { + @Test + public void testEquals_true() { + GithubSecurityRealm a = new GithubSecurityRealm(new String("http://jenkins.acme.com"), new String("http://jenkins.acme.com/api/v3"), new String("someid"), new String("somesecret"), new String("read:org")); + GithubSecurityRealm b = new GithubSecurityRealm(new String("http://jenkins.acme.com"), new String("http://jenkins.acme.com/api/v3"), new String("someid"), new String("somesecret"), new String("read:org")); + assertTrue(a.equals(b)); + } + @Test + public void testEquals_false() { + GithubSecurityRealm a = new GithubSecurityRealm(new String("http://jenkins.acme.com"), new String("http://jenkins.acme.com/api/v3"), new String("someid"), new String("somesecret"), new String("read:org")); + GithubSecurityRealm b = new GithubSecurityRealm(new String("http://jenkins.acme.com"), new String("http://jenkins.acme.com/api/v3"), new String("someid"), new String("somesecret"), new String("read:org,repo")); + assertFalse(a.equals(b)); + assertFalse(a.equals("")); + } +}