Skip to content
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
5 changes: 5 additions & 0 deletions flume-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
<artifactId>flume-ng-sdk</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-sdk-test</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-node</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions flume-ng-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@

<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-sdk</artifactId>
<classifier>tests</classifier>
<artifactId>flume-ng-sdk-test</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.apache.flume.event.SimpleEvent;
import org.apache.flume.exception.ChannelException;
import org.apache.flume.instrumentation.SinkCounter;
import org.apache.flume.util.Whitebox;
import org.apache.flume.sdk.test.Whitebox;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.After;
Expand Down
66 changes: 66 additions & 0 deletions flume-ng-sdk-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to you under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.flume</groupId>
<artifactId>flume-parent</artifactId>
<version>${revision}</version>
<relativePath>../flume-parent/pom.xml</relativePath>
</parent>

<artifactId>flume-ng-sdk-test</artifactId>
<name>Flume NG SDK Test</name>
<description>Test fixtures shared by the Flume modules.
The fixtures live in `main`, so that they are packaged in a regular JAR instead of a test JAR.</description>

<properties>
<!-- This artifact was never released before -->
<bnd.baseline.fail.on.missing>false</bnd.baseline.fail.on.missing>
<!-- `TestKeyStores.certificate()` hands out the `X509Certificate` it was built from, which SpotBugs
reports as exposing internal representation. -->
<spotbugs.maxAllowedViolations>1</spotbugs.maxAllowedViolations>
<module.name>org.apache.flume.sdk.test</module.name>
</properties>

<dependencies>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.util;
package org.apache.flume.sdk.test;

import java.io.OutputStream;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.util;
package org.apache.flume.sdk.test;

import org.apache.commons.lang3.reflect.FieldUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.util;
package org.apache.flume.sdk.test;

import java.math.BigInteger;
import java.security.KeyPair;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.sdk.test;

import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.KeyStore;
import java.security.cert.X509Certificate;
import org.junit.Assert;
import org.junit.Test;

public class TestSelfSignedKeyStores {

private static final String PASSWORD = "password";

@Test
public void testKeyStoreHoldsThePrivateKey() throws Exception {
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
KeyStore keyStore = credentials.keyStore("JKS", PASSWORD);

Assert.assertTrue(keyStore.isKeyEntry("key"));
Assert.assertEquals(credentials.certificate(), keyStore.getCertificateChain("key")[0]);
Assert.assertNotNull(keyStore.getKey("key", PASSWORD.toCharArray()));
}

@Test
public void testTrustStoreHoldsOnlyTheCertificate() throws Exception {
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
KeyStore trustStore = credentials.trustStore("JKS");

Assert.assertFalse(trustStore.isKeyEntry("cert"));
Assert.assertEquals(credentials.certificate(), trustStore.getCertificate("cert"));
}

@Test
public void testWrittenKeyStoreCanBeReloaded() throws Exception {
TestKeyStores credentials = TestKeyStores.selfSigned("CN=localhost");
Path file = Files.createTempFile("keystore", ".jks");
try {
credentials.writeKeyStore(file, "JKS", PASSWORD);

KeyStore reloaded = KeyStore.getInstance("JKS");
try (InputStream in = Files.newInputStream(file)) {
reloaded.load(in, PASSWORD.toCharArray());
}
X509Certificate certificate = (X509Certificate) reloaded.getCertificateChain("key")[0];
Assert.assertEquals(credentials.certificate(), certificate);
} finally {
Files.deleteIfExists(file);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.sdk.test;

import org.junit.Assert;
import org.junit.Test;

public class TestWhitebox {

private static final class Target {
private String value = "initial";
}

@Test
public void testGetInternalState() {
Assert.assertEquals("initial", Whitebox.getInternalState(new Target(), "value"));
}

@Test
public void testSetInternalState() {
Target target = new Target();
Whitebox.setInternalState(target, "value", "replaced");
Assert.assertEquals("replaced", target.value);
}

@Test(expected = RuntimeException.class)
public void testUnknownFieldFails() {
Whitebox.getInternalState(new Target(), "missing");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.flume.sdk.test;

import java.security.KeyPair;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.Date;
import org.junit.Assert;
import org.junit.Test;

public class TestX509Certificates {

@Test
public void testSelfSignedCertificate() throws Exception {
KeyPair keyPair = X509Certificates.generateKeyPair();
X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, "CN=localhost");

Assert.assertEquals(
"CN=localhost", certificate.getSubjectX500Principal().getName());
Assert.assertEquals(certificate.getSubjectX500Principal(), certificate.getIssuerX500Principal());
// A self-signed certificate verifies against its own public key.
certificate.verify(keyPair.getPublic());
certificate.checkValidity(new Date());
}

@Test
public void testServerCertificateExtensions() throws Exception {
KeyPair keyPair = X509Certificates.generateKeyPair();
X509Certificate certificate = X509Certificates.generateSelfSignedCertificate(keyPair, "CN=localhost");

// A negative path length constraint marks a certificate that is not a CA.
Assert.assertEquals(-1, certificate.getBasicConstraints());
Assert.assertEquals(Collections.singletonList("1.3.6.1.5.5.7.3.1"), certificate.getExtendedKeyUsage());
}

@Test
public void testKeyPairsAreDistinct() {
Assert.assertNotEquals(
X509Certificates.generateKeyPair().getPrivate(),
X509Certificates.generateKeyPair().getPrivate());
}
}
39 changes: 0 additions & 39 deletions flume-ng-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@
<scope>test</scope>
</dependency>

<!-- Used by the shared X509Certificates test helper (packaged in the test-jar). -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand All @@ -82,32 +69,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<!-- BND describes the main classes in a single manifest per module, which `logging-parent`
feeds to every execution. Drop it here: the test JAR is not that bundle, and its
Package URL needs the qualifiers of a classified artifact. -->
<archive combine.self="override">
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Purl>pkg:maven/${project.groupId}/${project.artifactId}@${project.version}?classifier=tests&amp;type=test-jar</Purl>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions flume-ng-sources/flume-http-source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
</dependency>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-sdk</artifactId>
<classifier>tests</classifier>
<artifactId>flume-ng-sdk-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
import org.apache.flume.conf.Configurables;
import org.apache.flume.event.JSONEvent;
import org.apache.flume.instrumentation.SourceCounter;
import org.apache.flume.util.TestKeyStores;
import org.apache.flume.util.Whitebox;
import org.apache.flume.sdk.test.TestKeyStores;
import org.apache.flume.sdk.test.Whitebox;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpOptions;
Expand Down
3 changes: 1 addition & 2 deletions flume-ng-sources/flume-syslog-source/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
</dependency>
<dependency>
<groupId>org.apache.flume</groupId>
<artifactId>flume-ng-sdk</artifactId>
<classifier>tests</classifier>
<artifactId>flume-ng-sdk-test</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
import org.apache.flume.conf.Configurables;
import org.apache.flume.exception.ChannelException;
import org.apache.flume.instrumentation.SourceCounter;
import org.apache.flume.sdk.test.TestKeyStores;
import org.apache.flume.sdk.test.Whitebox;
import org.apache.flume.source.syslog.MultiportSyslogTCPSource.LineSplitter;
import org.apache.flume.source.syslog.MultiportSyslogTCPSource.MultiportSyslogHandler;
import org.apache.flume.source.syslog.MultiportSyslogTCPSource.ParsedBuffer;
import org.apache.flume.source.syslog.MultiportSyslogTCPSource.ThreadSafeDecoder;
import org.apache.flume.util.TestKeyStores;
import org.apache.flume.util.Whitebox;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
Expand Down
Loading
Loading