| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.controls; |
| | | |
| | |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | import org.forgerock.opendj.io.ASN1; |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * Test password control. |
| | | */ |
| | | /** Test password control. */ |
| | | @SuppressWarnings("javadoc") |
| | | public class PasswordControlTest |
| | | extends ControlsTestCase |
| | | { |
| | | |
| | | /** |
| | | * Create values for PasswordPolicyErrorType. |
| | | */ |
| | | /** Create values for PasswordPolicyErrorType. */ |
| | | @DataProvider(name = "passwordPolicyErrorTypeData") |
| | | public Object[][] createPasswordPolicyErrorTypeData() |
| | | { |
| | |
| | | return new Object[][] { { values } }; |
| | | } |
| | | |
| | | /** |
| | | * Test if int value are ok. |
| | | */ |
| | | /** Test if int value are ok. */ |
| | | @Test(dataProvider = "passwordPolicyErrorTypeData") |
| | | public void checkIntValuePasswordPolicyErrorTypeTest( |
| | | HashMap<Integer, String> expectedValues) throws Exception |
| | | Map<Integer, String> expectedValues) throws Exception |
| | | { |
| | | for (Integer i : expectedValues.keySet()) |
| | | for (Map.Entry<Integer, String> entry : expectedValues.entrySet()) |
| | | { |
| | | PasswordPolicyErrorType val = PasswordPolicyErrorType.valueOf(i); |
| | | String expected = expectedValues.get(i); |
| | | PasswordPolicyErrorType val = PasswordPolicyErrorType.valueOf(entry.getKey()); |
| | | String expected = entry.getValue(); |
| | | assertEquals(val.toString(), expected); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Test If we have only the required values. |
| | | */ |
| | | /** Test If we have only the required values. */ |
| | | @Test(dataProvider = "passwordPolicyErrorTypeData") |
| | | public void checkRequiredValuesPasswordPolicyErrorTypeTest( |
| | | HashMap<Integer, String> exceptedValues) throws Exception |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Test invalid int values. |
| | | */ |
| | | /** Test invalid int values. */ |
| | | @Test(dataProvider = "passwordPolicyErrorTypeData") |
| | | public void checkInvalidIntPasswordPolicyErrorTypeTest( |
| | | HashMap<Integer, String> exceptedValues) throws Exception |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Create correct values. |
| | | */ |
| | | /** Create correct values. */ |
| | | @DataProvider(name = "passwordPolicyWarningTypeData") |
| | | public Object[][] createPasswordPolicyWarningTypeData() |
| | | { |
| | |
| | | return new Object[][] { { values } }; |
| | | } |
| | | |
| | | /** |
| | | * Test if byte values are ok. |
| | | */ |
| | | /** Test if byte values are ok. */ |
| | | @Test(dataProvider = "passwordPolicyWarningTypeData") |
| | | public void checkIntValuePasswordPolicyWarningTypeTest( |
| | | HashMap<Byte, String> expectedValues) throws Exception |
| | | { |
| | | for (byte i : expectedValues.keySet()) |
| | | for (Map.Entry<Byte, String> entry : expectedValues.entrySet()) |
| | | { |
| | | byte i = entry.getKey(); |
| | | PasswordPolicyWarningType val = PasswordPolicyWarningType.valueOf(i); |
| | | String expected = expectedValues.get(i); |
| | | String expected = entry.getValue(); |
| | | |
| | | assertEquals(val.toString(), expected); |
| | | assertEquals(i, val.getType()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Test If we have only the required values. |
| | | */ |
| | | /** Test If we have only the required values. */ |
| | | @Test(dataProvider = "passwordPolicyWarningTypeData") |
| | | public void checkRequiredValuesPasswordPolicyWarningTypeTest( |
| | | HashMap<Byte, String> exceptedValues) throws Exception |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Test invalid int values. |
| | | */ |
| | | /** Test invalid int values. */ |
| | | @Test(dataProvider = "passwordPolicyWarningTypeData") |
| | | public void checkInvalidIntPasswordPolicyWarningTypeTest( |
| | | HashMap<Integer, String> exceptedValues) throws Exception |
| | |
| | | Set<Integer> keys = exceptedValues.keySet(); |
| | | for (int i = 0x70; i < 0x90; i++) |
| | | { |
| | | byte b = new Integer(i).byteValue(); |
| | | byte b = Integer.valueOf(i).byteValue(); |
| | | if (!keys.contains(b)) |
| | | { |
| | | assertNull(PasswordPolicyWarningType.valueOf(b)); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Create values for PasswordExpiredControl. |
| | | */ |
| | | /** Create values for PasswordExpiredControl. */ |
| | | @DataProvider(name = "passwordExpiredControlData") |
| | | public Object[][] createPasswordExpiredControlData() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test OID. |
| | | */ |
| | | /** Test OID. */ |
| | | @Test |
| | | public void checkPasswordOID() throws Exception |
| | | { |
| | |
| | | //assertEquals(OID_PASSWORD_POLICY_CONTROL, ""); |
| | | } |
| | | |
| | | /** |
| | | * Test "Netscape password expired control" implementation. |
| | | */ |
| | | /** Test "Netscape password expired control" implementation. */ |
| | | @Test(dataProvider = "passwordExpiredControlData") |
| | | public void passwordExpiredControlTest( |
| | | boolean isCritical) throws Exception |
| | |
| | | assertEquals(pec.getOID(),OID_NS_PASSWORD_EXPIRED); |
| | | } |
| | | |
| | | /** |
| | | * Create values for PasswordControl. |
| | | */ |
| | | /** Create values for PasswordControl. */ |
| | | @DataProvider(name = "passwordExpiringControlData") |
| | | public Object[][] createPasswordExpiringControlData() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test "Netscape password expired control" implementation. |
| | | */ |
| | | /** Test "Netscape password expired control" implementation. */ |
| | | @Test(dataProvider = "passwordExpiringControlData") |
| | | public void passwordExpiringControlTest( |
| | | boolean isCritical, int sec) throws Exception |
| | |
| | | assertEquals(pec.getSecondsUntilExpiration(), sec); |
| | | } |
| | | |
| | | /** |
| | | * Create values for PasswordControl. |
| | | */ |
| | | /** Create values for PasswordControl. */ |
| | | @DataProvider(name = "passwordPolicyRequestControlData") |
| | | public Object[][] createPasswordPolicyRequestControlData() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test PasswordPolicyRequestControl. |
| | | */ |
| | | /** Test PasswordPolicyRequestControl. */ |
| | | @Test(dataProvider = "passwordPolicyRequestControlData") |
| | | public void passwordPolicyRequestControlTest( |
| | | boolean isCritical) throws Exception |
| | |
| | | assertEquals("PasswordPolicyRequestControl()", pec.toString()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Create values for PasswordControl. |
| | | */ |
| | | /** Create values for PasswordControl. */ |
| | | @DataProvider(name = "passwordPolicyResponseControl") |
| | | public Object[][] createPasswordPolicyResponseControlData() |
| | | { |
| | |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * Test PasswordPolicyResponseControl. |
| | | */ |
| | | /** Test PasswordPolicyResponseControl. */ |
| | | @Test(dataProvider = "passwordPolicyResponseControl") |
| | | public void passwordPolicyResponseControlTest(boolean isCritical, int warningValue) |
| | | throws Exception |
| | |
| | | assertNull(pprc.getWarningType()); |
| | | assertNull(pprc.getErrorType()); |
| | | |
| | | |
| | | // check constructor PasswordPolicyResponseControl |
| | | // (PasswordPolicyWarningType warningType, |
| | | // int warningValue, |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // check encode/decode |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(bsb); |
| | |
| | | "PasswordPolicyResponseControl(" + warningType + "=" + warningValue + ", " + errorType + ")" ; |
| | | assertEquals(pprc.toString(), toString); |
| | | |
| | | |
| | | // check null value for the control |
| | | try |
| | | { |
| | |
| | | { |
| | | } |
| | | |
| | | |
| | | // check null warning type |
| | | bsb.clear(); |
| | | control = new PasswordPolicyResponseControl(isCritical, |