private static final long serialVersionUID = 6281159885962014041L;
/** Regular expression to specify the structure of key names. */
- public static final String NAME_REGEXP = "[A-Za-z0-9\\-_\\.]+";
+ public static final String NAME_REGEXP = "^[A-Za-z0-9\\-_\\.]+$";
/** Regular expression to specify the structure of key versions. */
- public static final String VERSION_REGEXP = "[0-9.]+";
+ public static final String VERSION_REGEXP = "^(\\d+.){2}\\d+$";
/** Regular expression to specify the structure of key IDs. */
- public static final String KEY_ID_REGEXP = "[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]";
+ public static final String KEY_ID_REGEXP = "^[A-Za-z0-9\\-_\\.]+:(\\d+.){2}\\d+$";
/** Specifies the value for names in NULL keys. */
public static final String NULL_KEY_NAME = "NULL";
} catch (IllegalArgumentException e) {
assertEquals(
"parameter \"id\": value \"some bad key id\", "
- + "does not match regular expression \"[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]\"",
+ + "does not match regular expression \"" + PfKey.KEY_ID_REGEXP + "\"",
e.getMessage());
}
someKey4.setVersion("0.1.2");
PfConceptKey someKey4a = new PfConceptKey(someKey1);
- someKey4a.setVersion("0");
+ someKey4a.setVersion("0.0.0");
PfConceptKey someKey5 = new PfConceptKey(someKey1);
someKey5.setVersion("1.2.2");
PfConceptKey someKey6 = new PfConceptKey(someKey1);
- someKey6.setVersion("3");
+ someKey6.setVersion("3.0.0");
assertEquals("name:0.1.2", someKey4.getId());
nameField.setAccessible(false);
assertEquals(
"name invalid-parameter name with value Key Name "
- + "does not match regular expression [A-Za-z0-9\\-_\\.]+",
+ + "does not match regular expression " + PfKey.NAME_REGEXP,
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
versionField.setAccessible(false);
assertEquals(
"version invalid-parameter version with value Key Version "
- + "does not match regular expression [0-9.]+",
+ + "does not match regular expression " + PfKey.VERSION_REGEXP,
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
key1a.setVersion("1.2.3");
assertFalse(key1.isNewerThan(key1a));
- key1.setVersion("1");
+ key1.setVersion("1.0.0");
assertFalse(key1.isNewerThan(key1a));
- key1a.setVersion("1");
+ key1a.setVersion("1.0.0");
assertFalse(key1.isNewerThan(key1a));
PfReferenceKey refKey = new PfReferenceKey();
@Test
public void testmajorMinorPatch() {
- PfConceptKey key = new PfConceptKey("Key", "1");
+ PfConceptKey key = new PfConceptKey("Key", "1.0.0");
assertEquals(1, key.getMajorVersion());
assertEquals(0, key.getMinorVersion());
assertEquals(0, key.getPatchVersion());
- key = new PfConceptKey("Key", "1.2");
+ key = new PfConceptKey("Key", "1.2.0");
assertEquals(1, key.getMajorVersion());
assertEquals(2, key.getMinorVersion());
assertEquals(0, key.getPatchVersion());
parentNameField.setAccessible(false);
assertEquals(
"parentKeyName invalid-parameter parentKeyName with value Parent Name "
- + "does not match regular expression [A-Za-z0-9\\-_\\.]+",
+ + "does not match regular expression " + PfKey.NAME_REGEXP,
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
parentVersionField.setAccessible(false);
assertEquals(
"parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version "
- + "does not match regular expression [0-9.]+",
+ + "does not match regular expression " + PfKey.VERSION_REGEXP,
validationResult.getMessageList().get(0).getMessage());
} catch (Exception validationException) {
fail("test should not throw an exception");
* Delete legacy operational policy.
*
* @param policyId ID of the policy.
- * @param policyVersion version of the policy, set to null to get the latest policy
+ * @param policyVersion version of the policy
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
* Delete legacy guard policy.
*
* @param policyId ID of the policy.
- * @param policyVersion version of the policy, set to null to get the latest policy
+ * @param policyVersion version of the policy
* @return the deleted policy
* @throws PfModelException on errors deleting policies
*/
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getOperationalPolicy("policy_id", "10.9.8");
- }).hasMessage("no policy found for policy: policy_id:10.9.8");
+ databaseProvider.getOperationalPolicy("policy_id", "10");
+ }).hasMessage("no policy found for policy: policy_id:10");
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
}).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
- databaseProvider.deleteOperationalPolicy("policy_id", "55.44.33");
- }).hasMessage("no policy found for policy: policy_id:55.44.33");
+ databaseProvider.deleteOperationalPolicy("policy_id", "55");
+ }).hasMessage("no policy found for policy: policy_id:55");
assertThatThrownBy(() -> {
databaseProvider.getGuardPolicy("policy_id", null);
}).hasMessage("no policy found for policy: policy_id:null");
assertThatThrownBy(() -> {
- databaseProvider.getGuardPolicy("policy_id", "6.7.5");
- }).hasMessage("no policy found for policy: policy_id:6.7.5");
+ databaseProvider.getGuardPolicy("policy_id", "6");
+ }).hasMessage("no policy found for policy: policy_id:6");
assertThatThrownBy(() -> {
databaseProvider.createGuardPolicy(new LegacyGuardPolicyInput());
}).hasMessage("policy type for guard policy \"null\" unknown");
assertThatThrownBy(() -> {
- databaseProvider.deleteGuardPolicy("policy_id", "33.22.11");
- }).hasMessage("no policy found for policy: policy_id:33.22.11");
+ databaseProvider.deleteGuardPolicy("policy_id", "33");
+ }).hasMessage("no policy found for policy: policy_id:33");
assertEquals(0, databaseProvider.getPdpGroups("name").size());
assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
}
@Override
- public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId, final String policyVersion)
- throws PfModelException {
+ public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId,
+ @NonNull final String policyVersion) throws PfModelException {
return null;
}
}
@Override
- public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull String policyId, final String policyVersion)
- throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull String policyId,
+ @NonNull final String policyVersion) throws PfModelException {
return null;
}
}).hasMessage("policyVersion is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "");
- }).hasMessage("no policy found for policy: IDontExist:");
+ new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "0");
+ }).hasMessage("no policy found for policy: IDontExist:0");
createPolicyTypes();
}).hasMessage("policyVersion is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new LegacyProvider().deleteOperationalPolicy(pfDao, "IDontExist", "");
- }).hasMessage("no policy found for policy: IDontExist:");
+ new LegacyProvider().deleteOperationalPolicy(pfDao, "IDontExist", "0");
+ }).hasMessage("no policy found for policy: IDontExist:0");
createPolicyTypes();