use of com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean in project athenz by yahoo.
the class DynamicConfigTest method testStatic.
@Test
public void testStatic() throws IOException {
File configFile = File.createTempFile("ConfigProviderFileTest.testStatic", ".conf");
writeFile(configFile, "" + "string-key-ok: string-value\n" + "\n" + "int-key-ok: 100\n" + "int-key-too-big: 10000000000\n" + "int-key-invalid-1: x100\n" + "int-key-invalid-2: 100x\n" + "\n" + "long-key-ok: 100\n" + "long-key-too-big: 100000000000000000000\n" + "long-key-invalid-1: x100\n" + "long-key-invalid-2: 100x\n" + "\n" + "float-key-ok-1: 100\n" + "float-key-ok-2: 12.34\n" + "float-key-invalid-1: x100\n" + "float-key-invalid-2: 100x\n" + "\n" + "double-key-ok-1: 100\n" + "double-key-ok-2: 12.34\n" + "double-key-invalid-1: x100\n" + "double-key-invalid-2: 100x\n" + "\n" + "boolean-key-true: true\n" + "boolean-key-yes: yes\n" + "boolean-key-on: on\n" + "boolean-key-false: false\n" + "boolean-key-no: no\n" + "boolean-key-off: off\n" + "boolean-key-invalid: hmm...\n" + "\n" + "duration-key-reload: 10\n" + "duration-key-short: 100\n" + "duration-key-long: 100000\n" + "duration-key-too-big: 100000000000000000000\n" + "duration-key-invalid-1: x100\n" + "duration-key-invalid-2: 100x\n" + "\n" + "csv-key-ok: aaa,111,1234567890123456789,12.34,bbb\n");
try (ConfigManager configManager = new ConfigManager("duration-key-reload", 10, TimeUnit.MILLISECONDS).addProvider(new ConfigProviderFile()).addConfigSource("prop-file://" + configFile)) {
DynamicConfigString dynamicConfigStringOk = new DynamicConfigString(configManager, "string-key-ok", "default-value");
DynamicConfigString dynamicConfigStringMissing = new DynamicConfigString(configManager, "string-key-missing", "default-value");
DynamicConfigString dynamicConfigStringFixed = new DynamicConfigString("default-value");
DynamicConfigInteger dynamicConfigIntegerOk = new DynamicConfigInteger(configManager, "int-key-ok", 123456, 10, 1000);
DynamicConfigInteger dynamicConfigIntegerOverflow = new DynamicConfigInteger(configManager, "int-key-ok", 123456, 0, 10);
DynamicConfigInteger dynamicConfigIntegerUnderflow = new DynamicConfigInteger(configManager, "int-key-ok", 123456, 1000, 10000);
DynamicConfigInteger dynamicConfigIntegerTooBig = new DynamicConfigInteger(configManager, "int-key-too-big", 123456);
DynamicConfigInteger dynamicConfigIntegerInvalid1 = new DynamicConfigInteger(configManager, "int-key-invalid-1", 123456);
DynamicConfigInteger dynamicConfigIntegerInvalid2 = new DynamicConfigInteger(configManager, "int-key-invalid-2", 123456);
DynamicConfigInteger dynamicConfigIntegerMissing = new DynamicConfigInteger(configManager, "int-key-missing", 123456);
DynamicConfigInteger dynamicConfigIntegerFixed = new DynamicConfigInteger(123456);
DynamicConfigLong dynamicConfigLongOk = new DynamicConfigLong(configManager, "long-key-ok", 123456L, 10L, 1000L);
DynamicConfigLong dynamicConfigLongOverflow = new DynamicConfigLong(configManager, "long-key-ok", 123456L, 0L, 10L);
DynamicConfigLong dynamicConfigLongUnderflow = new DynamicConfigLong(configManager, "long-key-ok", 123456L, 1000L, 10000L);
DynamicConfigLong dynamicConfigLongTooBig = new DynamicConfigLong(configManager, "long-key-too-big", 123456L);
DynamicConfigLong dynamicConfigLongInvalid1 = new DynamicConfigLong(configManager, "long-key-invalid-1", 123456L);
DynamicConfigLong dynamicConfigLongInvalid2 = new DynamicConfigLong(configManager, "long-key-invalid-2", 123456L);
DynamicConfigLong dynamicConfigLongMissing = new DynamicConfigLong(configManager, "long-key-missing", 123456L);
DynamicConfigLong dynamicConfigLongFixed = new DynamicConfigLong(123456L);
DynamicConfigFloat dynamicConfigFloatOk1 = new DynamicConfigFloat(configManager, "float-key-ok-1", 1.23F, 10F, 1000F);
DynamicConfigFloat dynamicConfigFloatOk2 = new DynamicConfigFloat(configManager, "float-key-ok-2", 1.23F);
DynamicConfigFloat dynamicConfigFloatOverflow = new DynamicConfigFloat(configManager, "float-key-ok-1", 1.23F, 0F, 10F);
DynamicConfigFloat dynamicConfigFloatUnderflow = new DynamicConfigFloat(configManager, "float-key-ok-1", 1.23F, 1000F, 10000F);
DynamicConfigFloat dynamicConfigFloatInvalid1 = new DynamicConfigFloat(configManager, "float-key-invalid-1", 1.23F);
DynamicConfigFloat dynamicConfigFloatInvalid2 = new DynamicConfigFloat(configManager, "float-key-invalid-2", 1.23F);
DynamicConfigFloat dynamicConfigFloatMissing = new DynamicConfigFloat(configManager, "float-key-missing", 1.23F);
DynamicConfigFloat dynamicConfigFloatFixed = new DynamicConfigFloat(1.23F);
DynamicConfigDouble dynamicConfigDoubleOk1 = new DynamicConfigDouble(configManager, "double-key-ok-1", 123.456, 10.0, 1000.0);
DynamicConfigDouble dynamicConfigDoubleOk2 = new DynamicConfigDouble(configManager, "double-key-ok-2", 123.456);
DynamicConfigDouble dynamicConfigDoubleOverflow = new DynamicConfigDouble(configManager, "double-key-ok-1", 123.456, 0.0, 10.0);
DynamicConfigDouble dynamicConfigDoubleUnderflow = new DynamicConfigDouble(configManager, "double-key-ok-1", 123.456, 1000.0, 10000.0);
DynamicConfigDouble dynamicConfigDoubleInvalid1 = new DynamicConfigDouble(configManager, "double-key-invalid-1", 123.456);
DynamicConfigDouble dynamicConfigDoubleInvalid2 = new DynamicConfigDouble(configManager, "double-key-invalid-2", 123.456);
DynamicConfigDouble dynamicConfigDoubleMissing = new DynamicConfigDouble(configManager, "double-key-missing", 123.456);
DynamicConfigDouble dynamicConfigDoubleFixed = new DynamicConfigDouble(123.456);
DynamicConfigBoolean dynamicConfigBooleanTrueTrue = new DynamicConfigBoolean(configManager, "boolean-key-true", true);
DynamicConfigBoolean dynamicConfigBooleanTrueYes = new DynamicConfigBoolean(configManager, "boolean-key-yes", true);
DynamicConfigBoolean dynamicConfigBooleanTrueOn = new DynamicConfigBoolean(configManager, "boolean-key-on", true);
DynamicConfigBoolean dynamicConfigBooleanTrueFalse = new DynamicConfigBoolean(configManager, "boolean-key-false", true);
DynamicConfigBoolean dynamicConfigBooleanTrueNo = new DynamicConfigBoolean(configManager, "boolean-key-no", true);
DynamicConfigBoolean dynamicConfigBooleanTrueOff = new DynamicConfigBoolean(configManager, "boolean-key-off", true);
DynamicConfigBoolean dynamicConfigBooleanTrueInvalid = new DynamicConfigBoolean(configManager, "boolean-key-invalid", true);
DynamicConfigBoolean dynamicConfigBooleanTrueMissing = new DynamicConfigBoolean(configManager, "boolean-key-missing", true);
DynamicConfigBoolean dynamicConfigBooleanTrueFixed = new DynamicConfigBoolean(true);
DynamicConfigBoolean dynamicConfigBooleanFalseTrue = new DynamicConfigBoolean(configManager, "boolean-key-true", false);
DynamicConfigBoolean dynamicConfigBooleanFalseYes = new DynamicConfigBoolean(configManager, "boolean-key-yes", false);
DynamicConfigBoolean dynamicConfigBooleanFalseOn = new DynamicConfigBoolean(configManager, "boolean-key-on", false);
DynamicConfigBoolean dynamicConfigBooleanFalseFalse = new DynamicConfigBoolean(configManager, "boolean-key-false", false);
DynamicConfigBoolean dynamicConfigBooleanFalseNo = new DynamicConfigBoolean(configManager, "boolean-key-no", false);
DynamicConfigBoolean dynamicConfigBooleanFalseOff = new DynamicConfigBoolean(configManager, "boolean-key-off", false);
DynamicConfigBoolean dynamicConfigBooleanFalseInvalid = new DynamicConfigBoolean(configManager, "boolean-key-invalid", false);
DynamicConfigBoolean dynamicConfigBooleanFalseMissing = new DynamicConfigBoolean(configManager, "boolean-key-missing", false);
DynamicConfigBoolean dynamicConfigBooleanFalseFixed = new DynamicConfigBoolean(false);
DynamicConfigDuration dynamicConfigDurationShort = new DynamicConfigDuration(configManager, "duration-key-short", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationLong = new DynamicConfigDuration(configManager, "duration-key-long", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationTooBig = new DynamicConfigDuration(configManager, "duration-key-too-big", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationInvalid1 = new DynamicConfigDuration(configManager, "duration-key-invalid-1", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationInvalid2 = new DynamicConfigDuration(configManager, "duration-key-invalid-2", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationMissing = new DynamicConfigDuration(configManager, "duration-key-missing", 123456, TimeUnit.SECONDS);
DynamicConfigDuration dynamicConfigDurationFixed = new DynamicConfigDuration(123456, TimeUnit.SECONDS);
DynamicConfigCsv dynamicConfigCsvOk = new DynamicConfigCsv(configManager, "csv-key-ok", "default-value-a,default-value-b");
DynamicConfigCsv dynamicConfigCsvMissing = new DynamicConfigCsv(configManager, "csv-key-missing", "default-value-a,default-value-b");
DynamicConfigCsv dynamicConfigCsvFixed = new DynamicConfigCsv("fixed-value-a,fixed-value-b");
assertEquals("string-value", dynamicConfigStringOk.toString());
assertEquals("string-value", dynamicConfigStringOk.get());
assertEquals("default-value", dynamicConfigStringMissing.get());
assertEquals("default-value", dynamicConfigStringFixed.get());
assertEquals("100", dynamicConfigIntegerOk.toString());
assertEquals(Integer.valueOf(100), dynamicConfigIntegerOk.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerOverflow.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerUnderflow.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerTooBig.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerInvalid1.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerInvalid2.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerMissing.get());
assertEquals(Integer.valueOf(123456), dynamicConfigIntegerFixed.get());
assertEquals("100", dynamicConfigLongOk.toString());
assertEquals(Long.valueOf(100L), dynamicConfigLongOk.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongOverflow.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongUnderflow.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongTooBig.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongInvalid1.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongInvalid2.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongMissing.get());
assertEquals(Long.valueOf(123456L), dynamicConfigLongFixed.get());
assertEquals("12.34", dynamicConfigFloatOk2.toString());
assertEquals(Float.valueOf(100F), dynamicConfigFloatOk1.get());
assertEquals(Float.valueOf(12.34F), dynamicConfigFloatOk2.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatOverflow.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatUnderflow.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatInvalid1.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatInvalid2.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatMissing.get());
assertEquals(Float.valueOf(1.23F), dynamicConfigFloatFixed.get());
assertEquals("12.34", dynamicConfigDoubleOk2.toString());
assertEquals(Double.valueOf(100.0), dynamicConfigDoubleOk1.get());
assertEquals(Double.valueOf(12.34), dynamicConfigDoubleOk2.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleOverflow.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleUnderflow.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleInvalid1.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleInvalid2.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleMissing.get());
assertEquals(Double.valueOf(123.456), dynamicConfigDoubleFixed.get());
assertEquals("true", dynamicConfigBooleanTrueTrue.toString());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueTrue.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueYes.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueOn.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanTrueFalse.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanTrueNo.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanTrueOff.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueInvalid.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueMissing.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanTrueFixed.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanFalseTrue.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanFalseYes.get());
assertEquals(Boolean.TRUE, dynamicConfigBooleanFalseOn.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseFalse.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseNo.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseOff.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseInvalid.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseMissing.get());
assertEquals(Boolean.FALSE, dynamicConfigBooleanFalseFixed.get());
assertEquals(100_000L, dynamicConfigDurationShort.getMilliseconds());
assertEquals(100000_000L, dynamicConfigDurationLong.getMilliseconds());
assertEquals(123456_000L, dynamicConfigDurationTooBig.getMilliseconds());
assertEquals(123456_000L, dynamicConfigDurationInvalid1.getMilliseconds());
assertEquals(123456_000L, dynamicConfigDurationInvalid2.getMilliseconds());
assertEquals(123456_000L, dynamicConfigDurationMissing.getMilliseconds());
assertEquals(123456_000L, dynamicConfigDurationFixed.getMilliseconds());
assertEquals("[\"aaa\",\"111\",\"1234567890123456789\",\"12.34\",\"bbb\"]", Utils.jsonSerializeForLog(dynamicConfigCsvOk.getStringsList()));
assertEquals("[111.0,1.23456789012345677E18,12.34]", Utils.jsonSerializeForLog(dynamicConfigCsvOk.getDoublesList()));
assertEquals("[111.0,1.23456794E18,12.34]", Utils.jsonSerializeForLog(dynamicConfigCsvOk.getFloatsList()));
assertEquals("[111,1234567890123456789]", Utils.jsonSerializeForLog(dynamicConfigCsvOk.getLongsList()));
assertEquals("[111]", Utils.jsonSerializeForLog(dynamicConfigCsvOk.getIntegersList()));
assertEquals("[\"default-value-a\",\"default-value-b\"]", Utils.jsonSerializeForLog(dynamicConfigCsvMissing.getStringsList()));
assertEquals("[\"fixed-value-a\",\"fixed-value-b\"]", Utils.jsonSerializeForLog(dynamicConfigCsvFixed.getStringsList()));
assertTrue(dynamicConfigCsvOk.hasItem("aaa"));
assertFalse(dynamicConfigCsvOk.hasItem("ccc"));
assertTrue(dynamicConfigCsvOk.hasItem(12.34));
assertFalse(dynamicConfigCsvOk.hasItem(23.45));
assertTrue(dynamicConfigCsvOk.hasItem(12.34f));
assertFalse(dynamicConfigCsvOk.hasItem(23.45f));
assertTrue(dynamicConfigCsvOk.hasItem(1234567890123456789L));
assertFalse(dynamicConfigCsvOk.hasItem(222L));
assertTrue(dynamicConfigCsvOk.hasItem(111));
assertFalse(dynamicConfigCsvOk.hasItem(222));
}
@SuppressWarnings("unused") boolean deleted = configFile.delete();
}
use of com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean in project athenz by yahoo.
the class ZTSImplTest method getWorkloadsByIpROTest.
@Test
public void getWorkloadsByIpROTest() {
DynamicConfigBoolean dynamicConfigBoolean = Mockito.mock(DynamicConfigBoolean.class);
when(dynamicConfigBoolean.get()).thenReturn(true).thenReturn(false);
zts.readOnlyMode = dynamicConfigBoolean;
try {
Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
zts.getWorkloadsByIP(context, "10.0.0.1");
fail();
} catch (ResourceException re) {
assertEquals(ResourceException.BAD_REQUEST, re.getCode());
}
zts.readOnlyMode = dynamicConfigBoolean;
}
use of com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean in project athenz by yahoo.
the class ZTSImplTest method getWorkloadsByServiceROTest.
@Test
public void getWorkloadsByServiceROTest() {
DynamicConfigBoolean dynamicConfigBoolean = Mockito.mock(DynamicConfigBoolean.class);
when(dynamicConfigBoolean.get()).thenReturn(true).thenReturn(false);
zts.readOnlyMode = dynamicConfigBoolean;
try {
Principal principal = SimplePrincipal.create("user_domain", "user1", "v=U1;d=user_domain;n=user;s=signature", 0, null);
ResourceContext context = createResourceContext(principal);
zts.getWorkloadsByService(context, "transportrules", "api");
fail();
} catch (ResourceException re) {
assertEquals(ResourceException.BAD_REQUEST, re.getCode());
}
zts.readOnlyMode = dynamicConfigBoolean;
}
use of com.yahoo.athenz.common.server.util.config.dynamic.DynamicConfigBoolean in project athenz by yahoo.
the class ZTSImplTest method testReadOnlyMode.
@Test
public void testReadOnlyMode() {
ChangeLogStore structStore = new ZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", privateKey, "0");
DataStore store = new DataStore(structStore, null, ztsMetric);
ZTSImpl ztsImpl = new ZTSImpl(mockCloudStore, store);
DynamicConfigBoolean dynamicConfigBoolean = Mockito.mock(DynamicConfigBoolean.class);
when(dynamicConfigBoolean.get()).thenReturn(true);
ztsImpl.readOnlyMode = dynamicConfigBoolean;
PrincipalAuthority authority = new PrincipalAuthority();
SimplePrincipal principal = (SimplePrincipal) SimplePrincipal.create("athenz", "readonly", "v=S1;d=athenz;n=readonly;s=signature", 0, authority);
ResourceContext ctx = createResourceContext(principal);
try {
ztsImpl.postRoleCertificateRequest(ctx, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRegisterInformation(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRefreshInformation(ctx, null, null, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.deleteInstanceIdentity(ctx, null, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postInstanceRefreshRequest(ctx, null, null, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postSSHCertRequest(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
try {
ztsImpl.postRoleCertificateRequestExt(ctx, null);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), 400);
assertTrue(ex.getMessage().contains("Read-Only mode"));
}
}
Aggregations