Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automation equals methods #43

Merged
merged 1 commit into from
Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

/*
Expand Down Expand Up @@ -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<AuthorizationStrategy> {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHubSecurityRealm isn't final, so these could in fact still be different. I doubt that's relevant in practice though.

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
Expand Down
Original file line number Diff line number Diff line change
@@ -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(""));
}
}
Original file line number Diff line number Diff line change
@@ -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(""));
}
}