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()); }
@Test public void testPermittedOptions() { PermittedOptions options = new PermittedOptions(); assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress()); assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex()); assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority()); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match)); 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());
private boolean checkMatches(boolean inbound, String address, Map<String, Message<JsonObject>> replies) { // special case, when dealing with replies the addresses are not in the inbound/outbound list but on // the replies registry if (replies != null && inbound && replies.containsKey(address)) { return true; } List<PermittedOptions> matches = inbound ? options.getInboundPermitteds() : options.getOutboundPermitteds(); 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) { return true; } } return false; }
private boolean checkMatches(boolean inbound, String address, Map<String, Message<JsonObject>> replies) { // special case, when dealing with replies the addresses are not in the inbound/outbound list but on // the replies registry if (replies != null && inbound && replies.containsKey(address)) { return true; } List<PermittedOptions> matches = inbound ? options.getInboundPermitteds() : options.getOutboundPermitteds(); 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) { return true; } } return false; }
private boolean checkMatches(boolean inbound, String address, Object body) { List<PermittedOptions> matches = inbound ? options.getInboundPermitteds() : options.getOutboundPermitteds(); 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) { return structureMatches(matchHolder.getMatch(), body); } } return false; }
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()); }
@Test public void testPermittedOptions() { PermittedOptions options = new PermittedOptions(); assertEquals(PermittedOptions.DEFAULT_ADDRESS, options.getAddress()); assertEquals(PermittedOptions.DEFAULT_ADDRESS_REGEX, options.getAddressRegex()); assertEquals(PermittedOptions.DEFAULT_REQUIRED_AUTHORITY, options.getRequiredAuthority()); assertSame(options, options.setRequiredAuthority(requiredAuthority)); assertSame(options, options.setMatch(match)); 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());