Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Audit logs to OTLP test for MP Telemetry 2.0 #30833

Merged
merged 4 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#*******************************************************************************
# Copyright (c) 2024 IBM Corporation and others.
# Copyright (c) 2024, 2025 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
Expand Down Expand Up @@ -62,7 +62,11 @@ tested.features=mpTelemetry-2.0,\
pages-3.0,\
jsp-2.3,\
jsp-2.2,\
el-3.0
el-3.0,\
appsecurity-6.0,\
appsecurity-5.0,\
appsecurity-4.0,\
appsecurity-3.0

-buildpath: \
io.openliberty.jakarta.servlet.6.0;version=latest,\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* Copyright (c) 2024, 2025 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,6 +12,7 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -32,7 +33,6 @@
import componenttest.annotation.Server;
import componenttest.containers.SimpleLogConsumer;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.custom.junit.runner.RepeatTestFilter;
import componenttest.topology.impl.LibertyServer;
import io.openliberty.microprofile.telemetry.internal_fat.shared.TelemetryActions;

Expand All @@ -44,9 +44,12 @@ public class LoggingServletTest {
@Server("TelemetryLogsServer")
public static LibertyServer server;

public static final String APP_NAME = "MpTelemetryLogApp";

public static final String SERVER_XML_MSG_SOURCES = "msgSourceServer.xml";
public static final String SERVER_XML_TRACE_SOURCE = "traceSourceServer.xml";
public static final String SERVER_XML_FFDC_SOURCE = "FFDCSourceServer.xml";
public static final String SERVER_XML_AUDIT_SOURCE = "auditSourceServer.xml";

private static final String[] EXPECTED_FAILURES = { "CWMOT5005W", "SRVE0315E", "SRVE0777E" };

Expand Down Expand Up @@ -193,6 +196,58 @@ public void testFFDCLogs() throws Exception {
}
}

/*
* Ensures that audit events generated by a Liberty application are bridged over to the OTLP container.
*/
@Test
public void testAuditEventLogs() throws Exception {
assertTrue("The server was not started successfully.", server.isStarted());

TestUtils.isContainerStarted("LogsExporter", container);

RemoteFile messageLogFile = server.getDefaultLogFile();
setConfig(SERVER_XML_AUDIT_SOURCE, messageLogFile, server);

// Hit the application to trigger an audit event.
TestUtils.runApp(server, "logs");

//Allow time for the collector to receive and bridge logs.
TimeUnit.SECONDS.sleep(WAIT_TIMEOUT);

final String logs = container.getLogs();

// Verify audit event attributes generated by an application's audit event.
assertTrue("Audit type message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.type: Str(liberty_audit)"));
assertTrue("The Audit Event can not be found in the body.", TestUtils.assertLogContains("testAuditEventLogs", logs, "Body: Str(SECURITY_AUTHN)"));
assertTrue("The Audit event name attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.event_name: Str(SECURITY_AUTHN)"));
assertTrue("The Audit observer name attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.name: Str(SecurityService)"));
assertTrue("The Audit observer type URI attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.observer.type_uri: Str(service/server)"));
assertTrue("The Audit outcome attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.outcome: Str(success)"));
assertTrue("The Audit reason code attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_code: Str(200)"));
assertTrue("The Audit reason type attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.reason.reason_type: Str(HTTP)"));
assertTrue("The Audit target app name attribute can not be found.", TestUtils
.assertLogContains("testAuditEventLogs", logs,
"io.openliberty.audit.target.appname: Str(io.openliberty.microprofile.telemetry.logging.internal.container.fat.MpTelemetryLogApp.LogServlet)"));
assertTrue("The Audit target method attribute can not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.method: Str(GET)"));
assertTrue("The Audit target name attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.name: Str(/MpTelemetryLogApp/LogURL)"));
assertTrue("The Audit target realm attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.realm: Str(defaultRealm)"));
assertTrue("The Audit target type URI attribute can not be found.",
TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.audit.target.type_uri: Str(service/application/web)"));

// Verify common Logging attributes
assertTrue("SeverityNumber message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "SeverityNumber: Info2(10)"));
assertTrue("Sequence message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "io.openliberty.sequence: Str"));
assertTrue("Thread ID message could not be found.", TestUtils.assertLogContains("testAuditEventLogs", logs, "thread.id: Int"));

}

@AfterClass
public static void tearDown() throws Exception {
//catch if a server is still running.
Expand All @@ -201,10 +256,10 @@ public static void tearDown() throws Exception {
}
}

private static String setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception {
private static void setConfig(String fileName, RemoteFile logFile, LibertyServer server) throws Exception {
server.setMarkToEndOfLog(logFile);
server.setServerConfigurationFile(fileName);
return server.waitForStringInLogUsingMark("CWWKG0017I.*|CWWKG0018I.*");
server.waitForConfigUpdateInLogUsingMark(Collections.singleton(APP_NAME), new String[] {});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<server>
<featureManager>
<feature>audit-1.0</feature>
<feature>mpTelemetry-2.0</feature>
<feature>servlet-6.1</feature>
<feature>appSecurity-6.0</feature>
</featureManager>

<include location="../fatTestPorts.xml" />

<keyStore id="defaultKeyStore" password="Liberty"/>

<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="${bvt.prop.HTTP_default}"
httpsPort="${bvt.prop.HTTP_default.secure}" />

<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<applicationMonitor updateTrigger="mbean"/>

<!--Java2 security-->
<javaPermission className="java.security.AllPermission" name="*" actions="*" />

<mpTelemetry source="audit"/>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Dcom.ibm.ws.beta.edition=true