use of com.newrelic.agent.ForceDisconnectException in project newrelic-java-agent by newrelic.
the class LaspPoliciesConfigTest method noDisconnect.
@Test
public void noDisconnect() throws ParseException, ForceDisconnectException {
String policiesString = "{" + "\"record_sql\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false },\n" + "\"allow_raw_exception_messages\": { \"enabled\": false, \"required\": false },\n" + "\"custom_events\": { \"enabled\": false, \"required\": false },\n" + "\"custom_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"custom_instrumentation_editor\": { \"enabled\": false, \"required\": false },\n" + "\"message_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false },\n" + "\"job_arguments\": { \"enabled\": false, \"required\": false }}";
JSONObject policiesJson = createPolicies(policiesString);
try {
LaspPolicies.validatePolicies(policiesJson);
} catch (ForceDisconnectException ex) {
fail();
}
}
use of com.newrelic.agent.ForceDisconnectException in project newrelic-java-agent by newrelic.
the class LaspPoliciesConfigTest method jobArgumentsRequired.
@Test
public void jobArgumentsRequired() throws ParseException {
String policiesString = "{" + "\"job_arguments\": { \"enabled\": true, \"required\": true },\n" + "\"record_sql\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false },\n" + "\"allow_raw_exception_messages\": { \"enabled\": false, \"required\": false },\n" + "\"custom_events\": { \"enabled\": false, \"required\": false },\n" + "\"custom_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"custom_instrumentation_editor\": { \"enabled\": false, \"required\": false },\n" + "\"message_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false }}";
JSONObject policiesJson = createPolicies(policiesString);
try {
LaspPolicies.validatePolicies(policiesJson);
fail();
} catch (ForceDisconnectException ex) {
}
}
use of com.newrelic.agent.ForceDisconnectException in project newrelic-java-agent by newrelic.
the class LaspPoliciesConfigTest method unknownRequired.
@Test
public void unknownRequired() throws ParseException {
String policiesString = "{" + "\"totally_required_yo\": { \"enabled\": true, \"required\": true },\n" + "\"record_sql\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false },\n" + "\"allow_raw_exception_messages\": { \"enabled\": false, \"required\": false },\n" + "\"custom_events\": { \"enabled\": false, \"required\": false },\n" + "\"custom_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"custom_instrumentation_editor\": { \"enabled\": false, \"required\": false },\n" + "\"message_parameters\": { \"enabled\": false, \"required\": false },\n" + "\"attributes_include\": { \"enabled\": false, \"required\": false },\n" + "\"job_arguments\": { \"enabled\": false, \"required\": false }}";
JSONObject policiesJson = createPolicies(policiesString);
try {
LaspPolicies.validatePolicies(policiesJson);
fail();
} catch (ForceDisconnectException ex) {
}
}
use of com.newrelic.agent.ForceDisconnectException in project newrelic-java-agent by newrelic.
the class LaspPolicies method validatePolicies.
public static Map<String, Boolean> validatePolicies(JSONObject policies) throws ForceDisconnectException {
if (policies == null) {
return Collections.emptyMap();
}
Agent.LOG.log(Level.INFO, "LASP Policies received from server side: {0}", policies);
Map<String, Boolean> validatedPolicies = new HashMap<>();
Set<Map.Entry<String, JSONObject>> policyEntries = policies.entrySet();
for (Map.Entry<String, JSONObject> entry : policyEntries) {
String key = entry.getKey();
JSONObject value = entry.getValue();
if ((Boolean) value.get(REQUIRED) && !KNOWN_LASP_POLICIES.contains(key)) {
throw new ForceDisconnectException("Found unknown policy that is required: " + key);
}
// only store known/applicable policies
if (KNOWN_LASP_POLICIES.contains(key)) {
validatedPolicies.put(key, (Boolean) value.get(ENABLED));
}
}
// check to see if known policies is missing a policy the agent expected
for (String knownPolicy : KNOWN_LASP_POLICIES) {
if (!validatedPolicies.containsKey(knownPolicy)) {
throw new ForceDisconnectException("Did not receive all policies on preconnect");
}
}
return validatedPolicies;
}
Aggregations