mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-21 19:41:36 +01:00
remove deprecated stuff
This commit is contained in:
@@ -1,300 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.security.ScmSecurityException;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.web.security.WebSecurityContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Ignore
|
||||
public class PermissionUtilTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public PermissionUtilTest()
|
||||
{
|
||||
admams.getUser().setAdmin(true);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test(expected = ScmSecurityException.class)
|
||||
public void assertFailedPermissionTest()
|
||||
{
|
||||
PermissionUtil.assertPermission(repository, dent, PermissionType.WRITE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void assertPermissionTest()
|
||||
{
|
||||
PermissionUtil.assertPermission(repository, dent, PermissionType.READ);
|
||||
PermissionUtil.assertPermission(repository, perfect, PermissionType.READ);
|
||||
PermissionUtil.assertPermission(repository, perfect, PermissionType.WRITE);
|
||||
PermissionUtil.assertPermission(repository, marvin, PermissionType.READ);
|
||||
PermissionUtil.assertPermission(repository, marvin, PermissionType.WRITE);
|
||||
PermissionUtil.assertPermission(repository, marvin, PermissionType.OWNER);
|
||||
PermissionUtil.assertPermission(repository, admams, PermissionType.READ);
|
||||
PermissionUtil.assertPermission(repository, admams, PermissionType.WRITE);
|
||||
PermissionUtil.assertPermission(repository, admams, PermissionType.OWNER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
repository = new Repository();
|
||||
|
||||
Permission[] permissions = new Permission[] {
|
||||
new Permission("dent", PermissionType.READ),
|
||||
new Permission("perfect", PermissionType.WRITE),
|
||||
new Permission("marvin", PermissionType.OWNER) };
|
||||
|
||||
repository.setPermissions(Arrays.asList(permissions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testGroupPermissions()
|
||||
{
|
||||
WebSecurityContext dent = mockGroupCtx(new User("dent", "Arthur Dent",
|
||||
"arthur.dent@hitchhiker.com"), "devel", "qa");
|
||||
WebSecurityContext ford = mockGroupCtx(new User("ford", "Ford Prefect",
|
||||
"ford.prefect@hitchhiker.com"), "devel");
|
||||
WebSecurityContext zaphod = mockGroupCtx(new User("zaphod",
|
||||
"Zaphod Beeblebrox",
|
||||
"zaphod.beeblebrox@hitchhiker.com"), "qa");
|
||||
WebSecurityContext trillian = mockGroupCtx(new User("trillian",
|
||||
"Trillian Astra",
|
||||
"trillian.astra@hitchhiker.com"));
|
||||
Repository r = new Repository();
|
||||
|
||||
r.setPermissions(
|
||||
new ArrayList<Permission>(
|
||||
Arrays.asList(
|
||||
new Permission("dent"),
|
||||
new Permission("devel", PermissionType.WRITE, true),
|
||||
new Permission("qa", PermissionType.READ, true))));
|
||||
|
||||
// member of both devel and qa
|
||||
assertTrue(PermissionUtil.hasPermission(r, dent, PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(r, dent, PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(r, dent, PermissionType.OWNER));
|
||||
|
||||
// now, additionally the owner
|
||||
r.getPermissions().add(new Permission("dent", PermissionType.OWNER));
|
||||
assertTrue(PermissionUtil.hasPermission(r, dent, PermissionType.OWNER));
|
||||
|
||||
// member of just devel
|
||||
assertTrue(PermissionUtil.hasPermission(r, ford, PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(r, ford, PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(r, ford, PermissionType.OWNER));
|
||||
|
||||
// member of just qa
|
||||
assertTrue(PermissionUtil.hasPermission(r, zaphod, PermissionType.READ));
|
||||
assertFalse(PermissionUtil.hasPermission(r, zaphod, PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(r, zaphod, PermissionType.OWNER));
|
||||
|
||||
// member of no groups
|
||||
assertFalse(PermissionUtil.hasPermission(r, trillian, PermissionType.READ));
|
||||
assertFalse(PermissionUtil.hasPermission(r, trillian,
|
||||
PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(r, trillian,
|
||||
PermissionType.OWNER));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testIsWritable()
|
||||
{
|
||||
ScmConfiguration configuration = new ScmConfiguration();
|
||||
|
||||
configuration.setEnableRepositoryArchive(true);
|
||||
assertTrue(PermissionUtil.isWritable(configuration, repository, perfect));
|
||||
repository.setArchived(true);
|
||||
assertFalse(PermissionUtil.isWritable(configuration, repository, perfect));
|
||||
assertFalse(PermissionUtil.isWritable(configuration, repository, admams));
|
||||
configuration.setEnableRepositoryArchive(false);
|
||||
assertTrue(PermissionUtil.isWritable(configuration, repository, perfect));
|
||||
assertTrue(PermissionUtil.isWritable(configuration, repository, admams));
|
||||
assertFalse(PermissionUtil.isWritable(configuration, repository, dent));
|
||||
configuration.setEnableRepositoryArchive(true);
|
||||
repository.setArchived(false);
|
||||
assertTrue(PermissionUtil.isWritable(configuration, repository, perfect));
|
||||
assertTrue(PermissionUtil.isWritable(configuration, repository, admams));
|
||||
assertFalse(PermissionUtil.isWritable(configuration, repository, dent));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void hasPermissionTest()
|
||||
{
|
||||
assertTrue(PermissionUtil.hasPermission(repository, dent,
|
||||
PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, perfect,
|
||||
PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, perfect,
|
||||
PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(repository, dent,
|
||||
PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(repository, slarti,
|
||||
PermissionType.WRITE));
|
||||
assertFalse(PermissionUtil.hasPermission(repository, slarti,
|
||||
PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, marvin,
|
||||
PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, marvin,
|
||||
PermissionType.WRITE));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, marvin,
|
||||
PermissionType.OWNER));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, admams,
|
||||
PermissionType.READ));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, admams,
|
||||
PermissionType.WRITE));
|
||||
assertTrue(PermissionUtil.hasPermission(repository, admams,
|
||||
PermissionType.OWNER));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private WebSecurityContext mockCtx(User user)
|
||||
{
|
||||
WebSecurityContext context = mock(WebSecurityContext.class);
|
||||
|
||||
when(context.getUser()).thenReturn(user);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param user
|
||||
* @param groups
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private WebSecurityContext mockGroupCtx(User user, String... groups)
|
||||
{
|
||||
WebSecurityContext context = mockCtx(user);
|
||||
Set<String> groupSet = new HashSet<String>(Arrays.asList(groups));
|
||||
|
||||
when(context.getGroups()).thenReturn(groupSet);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private WebSecurityContext dent = mockCtx(new User("dent", "Arthur Dent",
|
||||
"arthur.dent@hitchhiker.com"));
|
||||
|
||||
/** Field description */
|
||||
private WebSecurityContext perfect = mockCtx(new User("perfect",
|
||||
"Ford Prefect",
|
||||
"ford.perfect@hitchhiker.com"));
|
||||
|
||||
/** Field description */
|
||||
private Repository repository;
|
||||
|
||||
/** Field description */
|
||||
private WebSecurityContext slarti = mockCtx(new User("slarti",
|
||||
"Slartibartfaß",
|
||||
"slartibartfass@hitchhiker.com"));
|
||||
|
||||
/** Field description */
|
||||
private WebSecurityContext marvin = mockCtx(new User("marvin", "Marvin",
|
||||
"paranoid.android@hitchhiker.com"));
|
||||
|
||||
/** Field description */
|
||||
private WebSecurityContext admams = mockCtx(new User("adams",
|
||||
"Douglas Adams",
|
||||
"douglas.adams@hitchhiker.com"));
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class HashBuilderTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract HashBuilder createHashBuilder();
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getLable();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateIteratedSaltedHash()
|
||||
{
|
||||
HashBuilder hashBuilder = createHashBuilder();
|
||||
String hash = hashBuilder.setIterations(1000).createSalt().setValue(
|
||||
"hitcheker").toHexString();
|
||||
byte[] salt = hashBuilder.getSalt();
|
||||
|
||||
hashBuilder = createHashBuilder();
|
||||
|
||||
String otherHash = hashBuilder.setIterations(1000).setSalt(salt).setValue(
|
||||
"hitcheker").toHexString();
|
||||
|
||||
checkHash("hitcheker", hash, otherHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateLabledHash()
|
||||
{
|
||||
HashBuilder hashBuilder = createHashBuilder();
|
||||
String hash = hashBuilder.enableLabel().setValue("hitcheker").toHexString();
|
||||
|
||||
System.out.println(hash);
|
||||
checkHash("hitcheker", hash);
|
||||
|
||||
Pattern p = Pattern.compile("\\{([^\\}]+)\\}.*");
|
||||
Matcher m = p.matcher(hash);
|
||||
|
||||
assertTrue(m.matches());
|
||||
|
||||
String lable = m.group(1);
|
||||
|
||||
assertNotNull(lable);
|
||||
assertEquals(getLable(), lable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateSalt()
|
||||
{
|
||||
HashBuilder hashBuilder = createHashBuilder();
|
||||
|
||||
assertNotNull(hashBuilder);
|
||||
|
||||
byte[] salt = hashBuilder.createSalt().getSalt();
|
||||
|
||||
assertNotNull(salt);
|
||||
|
||||
byte[] otherSalt = hashBuilder.createSalt().getSalt();
|
||||
|
||||
assertNotNull(otherSalt);
|
||||
assertEquals(salt.length, otherSalt.length);
|
||||
assertThat(salt, not(equalTo(otherSalt)));
|
||||
salt = hashBuilder.createSalt(4).getSalt();
|
||||
assertEquals(4, salt.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateSaltedHash()
|
||||
{
|
||||
HashBuilder hashBuilder = createHashBuilder();
|
||||
String hash = hashBuilder.createSalt().setValue("hitcheker").toHexString();
|
||||
byte[] salt = hashBuilder.getSalt();
|
||||
|
||||
hashBuilder = createHashBuilder();
|
||||
|
||||
String otherHash =
|
||||
hashBuilder.setSalt(salt).setValue("hitcheker").toHexString();
|
||||
|
||||
checkHash("hitcheker", hash, otherHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCreateSimpleHash()
|
||||
{
|
||||
HashBuilder hashBuilder = createHashBuilder();
|
||||
String hash = hashBuilder.setValue("hitcheker").toHexString();
|
||||
|
||||
hashBuilder = createHashBuilder();
|
||||
|
||||
String otherHash = hashBuilder.setValue("hitcheker").toHexString();
|
||||
|
||||
checkHash("hitcheker", hash, otherHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plain
|
||||
* @param hash
|
||||
*/
|
||||
private void checkHash(String plain, String hash)
|
||||
{
|
||||
assertNotNull(hash);
|
||||
assertThat(hash, not(equalTo(plain)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param plain
|
||||
* @param hash
|
||||
* @param otherHash
|
||||
*/
|
||||
private void checkHash(String plain, String hash, String otherHash)
|
||||
{
|
||||
checkHash(plain, hash);
|
||||
assertNotNull(otherHash);
|
||||
assertThat(otherHash, not(equalTo("hitcheker")));
|
||||
assertEquals(hash, otherHash);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MD5HashBuilderTest extends HashBuilderTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HashBuilder createHashBuilder()
|
||||
{
|
||||
return new MD5HashBuilder();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getLable()
|
||||
{
|
||||
return MD5HashBuilder.DIGEST;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MessageDigestHashBuilderTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testExtractor()
|
||||
{
|
||||
MessageDigestHashBuilder hashBuilder = new SHA1HashBuilder("hitcheker");
|
||||
String hash =
|
||||
hashBuilder.enableLabel().createSalt().appendSalt().toHexString();
|
||||
|
||||
assertNotNull(hash);
|
||||
hashBuilder =
|
||||
MessageDigestHashBuilder.createExtractor(hash).getHashBuilder(8);
|
||||
assertEquals(hash, hashBuilder.setValue("hitcheker").toHexString());
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SHA1HashBuilderTest extends HashBuilderTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HashBuilder createHashBuilder()
|
||||
{
|
||||
return new SHA1HashBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testCompatibility()
|
||||
{
|
||||
MessageDigestEncryptionHandler mdeh = new MessageDigestEncryptionHandler();
|
||||
String hash = mdeh.encrypt("trillian123");
|
||||
String newHash = createHashBuilder().setValue("trillian123").toHexString();
|
||||
|
||||
assertEquals(hash, newHash);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getLable()
|
||||
{
|
||||
return SHA1HashBuilder.DIGEST;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.security;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class SHA512HashBuilderTest extends HashBuilderTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HashBuilder createHashBuilder()
|
||||
{
|
||||
return new SHA512HashBuilder();
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getLable()
|
||||
{
|
||||
return SHA512HashBuilder.DIGEST;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user