private Match checkMatches(boolean inbound, String address, Object body) { List<PermittedOptions> matches = inbound ? inboundPermitted : outboundPermitted; for (PermittedOptions matchHolder : matches) { String matchAddress = matchHolder.getAddress(); String matchRegex; if (matchAddress == null) { matchRegex = matchHolder.getAddressRegex(); } else { matchRegex = null; } boolean addressOK; if (matchAddress == null) { addressOK = matchRegex == null || regexMatches(matchRegex, address); } else { addressOK = matchAddress.equals(address); } if (addressOK) { boolean matched = structureMatches(matchHolder.getMatch(), body); if (matched) { String requiredAuthority = matchHolder.getRequiredAuthority(); return new Match(true, requiredAuthority); } } } return new Match(false); }
@Test public void testPermittedOptionsJson() { String address = TestUtils.randomAlphaString(10); String addressRegex = TestUtils.randomAlphaString(10); String requiredAuthority = TestUtils.randomAlphaString(10); JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)); JsonObject json = new JsonObject(). put("address", address). put("addressRegex", addressRegex). put("requiredAuthority", requiredAuthority). put("match", match); PermittedOptions options = new PermittedOptions(json); assertEquals(address, options.getAddress()); assertEquals(addressRegex, options.getAddressRegex()); assertEquals(requiredAuthority, options.getRequiredAuthority()); assertEquals(match, options.getMatch()); }
assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress()); assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex()); assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority()); assertEquals(PermittedOptions.DEFAULT_MATCH, options.getMatch()); String address = TestUtils.randomAlphaString(10); assertEquals(address, options.getAddress()); assertEquals(addressRegex, options.getAddressRegex()); assertEquals(requiredAuthority, options.getRequiredAuthority()); assertEquals(match, options.getMatch()); PermittedOptions copy = new PermittedOptions(options); assertEquals(address, copy.getAddress()); assertEquals(addressRegex, copy.getAddressRegex()); assertEquals(requiredAuthority, copy.getRequiredAuthority()); assertEquals(match, copy.getMatch()); assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10)));
private Match checkMatches(boolean inbound, String address, Object body) { List<PermittedOptions> matches = inbound ? inboundPermitted : outboundPermitted; for (PermittedOptions matchHolder : matches) { String matchAddress = matchHolder.getAddress(); String matchRegex; if (matchAddress == null) { matchRegex = matchHolder.getAddressRegex(); } else { matchRegex = null; } boolean addressOK; if (matchAddress == null) { addressOK = matchRegex == null || regexMatches(matchRegex, address); } else { addressOK = matchAddress.equals(address); } if (addressOK) { boolean matched = structureMatches(matchHolder.getMatch(), body); if (matched) { String requiredAuthority = matchHolder.getRequiredAuthority(); return new Match(true, requiredAuthority); } } } return new Match(false); }
@Test public void testPermittedOptionsJson() { String address = TestUtils.randomAlphaString(10); String addressRegex = TestUtils.randomAlphaString(10); String requiredAuthority = TestUtils.randomAlphaString(10); JsonObject match = new JsonObject().put(TestUtils.randomAlphaString(10), TestUtils.randomAlphaString(10)); JsonObject json = new JsonObject(). put("address", address). put("addressRegex", addressRegex). put("requiredAuthority", requiredAuthority). put("match", match); PermittedOptions options = new PermittedOptions(json); assertEquals(address, options.getAddress()); assertEquals(addressRegex, options.getAddressRegex()); assertEquals(requiredAuthority, options.getRequiredAuthority()); assertEquals(match, options.getMatch()); }
assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress()); assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex()); assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority()); assertEquals(PermittedOptions.DEFAULT_MATCH, options.getMatch()); String address = TestUtils.randomAlphaString(10); assertEquals(address, options.getAddress()); assertEquals(addressRegex, options.getAddressRegex()); assertEquals(requiredAuthority, options.getRequiredAuthority()); assertEquals(match, options.getMatch()); PermittedOptions copy = new PermittedOptions(options); assertEquals(address, copy.getAddress()); assertEquals(addressRegex, copy.getAddressRegex()); assertEquals(requiredAuthority, copy.getRequiredAuthority()); assertEquals(match, copy.getMatch()); assertSame(copy, copy.setAddress(TestUtils.randomAlphaString(10)));