Skip to content

Commit

Permalink
Merge pull request #527 from jpmorganchase/patch-release-0.7.1
Browse files Browse the repository at this point in the history
Patch release 0.7.3 branch back to master
  • Loading branch information
Krish1979 authored Nov 19, 2018
2 parents 470153e + 90b8002 commit 1b8fc88
Show file tree
Hide file tree
Showing 67 changed files with 769 additions and 134 deletions.
2 changes: 1 addition & 1 deletion argon2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
</dependencies>


</project>
</project>
2 changes: 1 addition & 1 deletion config-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@



</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.UUID;

import static com.quorum.tessera.test.util.ElUtil.createAndPopulatePaths;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void withConstraintViolations() throws Exception {
cliDelegate.execute("-configfile", configFile.toString());
failBecauseExceptionWasNotThrown(ConstraintViolationException.class);
} catch (ConstraintViolationException ex) {
assertThat(ex.getConstraintViolations()).hasSize(2);
assertThat(ex.getConstraintViolations()).hasSize(4);

}

Expand All @@ -113,7 +114,13 @@ public void keygenWithConfig() throws Exception {

KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();

FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));
Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

Path unixSocketPath = Files.createTempFile(UUID.randomUUID().toString(), ".ipc");
Expand Down Expand Up @@ -175,8 +182,14 @@ public void outputWithoutKeygenOrConfig() {
public void output() throws Exception {

KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();

FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));

Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

Path generatedKey = Paths.get("/tmp/" + UUID.randomUUID().toString());
Expand Down Expand Up @@ -355,7 +368,13 @@ public void suppressStartupForKeygenOption() throws Exception {
@Test
public void allowStartupForKeygenAndConfigfileOptions() throws Exception {
final KeyGenerator keyGenerator = MockKeyGeneratorFactory.getMockKeyGenerator();
final FilesystemKeyPair keypair = new FilesystemKeyPair(Paths.get(""), Paths.get(""));
Path publicKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");
Path privateKeyPath = Files.createTempFile(UUID.randomUUID().toString(), "");

Files.write(privateKeyPath, Arrays.asList("SOMEDATA"));
Files.write(publicKeyPath, Arrays.asList("SOMEDATA"));

FilesystemKeyPair keypair = new FilesystemKeyPair(publicKeyPath, privateKeyPath);
when(keyGenerator.generate(anyString(), eq(null))).thenReturn(keypair);

final Path configFile = createAndPopulatePaths(getClass().getResource("/sample-config.json"));
Expand Down
2 changes: 1 addition & 1 deletion config-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@
</plugins>
</build>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ public void ifConfigParameterIsNotSetInTomlOrCliThenDefaultIsUsed() throws Excep
Path configFile = Files.createTempFile("emptyConfig", ".txt");
Path keysFile = Paths.get("abcxyz");
Files.deleteIfExists(keysFile);
Files.createFile(Paths.get("abcxyz"));
Files.createFile(keysFile);
Files.write(keysFile, Arrays.asList("SOMEDATA"));

String[] requiredParams = {
"--tomlfile=" + configFile.toString(),
Expand Down
2 changes: 1 addition & 1 deletion config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.quorum.tessera.config.constraints;

import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;

@Target({FIELD, METHOD, PARAMETER, ANNOTATION_TYPE, TYPE_PARAMETER, TYPE_USE})
@Retention(RUNTIME)
@Constraint(validatedBy = ValidContentValidator.class)
@Documented
public @interface ValidContent {

String message() default "{ValidContent.message}";

Class<?>[] groups() default {};

Class<? extends Payload>[] payload() default {};

int minLines() default 0;

int maxLines() default Integer.MAX_VALUE;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.quorum.tessera.config.constraints;

import com.quorum.tessera.io.FilesDelegate;
import java.nio.file.Files;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ValidContentValidator implements ConstraintValidator<ValidContent, Path> {

private ValidContent config;

@Override
public void initialize(ValidContent constraintAnnotation) {
this.config = constraintAnnotation;
}

@Override
public boolean isValid(Path path, ConstraintValidatorContext context) {

if (Objects.isNull(path)) {
return true;
}

if (!Files.exists(path)) {
return true;
}

List<String> lines = FilesDelegate.create().lines(path)
.filter(line -> !Objects.equals("", line))
.collect(Collectors.toList());

return lines.size() >= config.minLines() && lines.size() <= config.maxLines();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import com.quorum.tessera.config.constraints.ValidBase64;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;

public class DirectKeyPair implements ConfigKeyPair {

@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
private final String publicKey;


@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.quorum.tessera.config.KeyDataConfig;
import com.quorum.tessera.config.adapters.PathAdapter;
import com.quorum.tessera.config.constraints.ValidContent;
import com.quorum.tessera.config.constraints.ValidPath;
import com.quorum.tessera.config.util.JaxbUtil;
import com.quorum.tessera.io.IOCallback;
Expand All @@ -16,12 +17,14 @@

public class FilesystemKeyPair implements ConfigKeyPair {

@ValidContent(minLines = 1,maxLines = 1,message = "file expected to contain a single non empty value")
@NotNull
@ValidPath(checkExists = true, message = "File does not exist")
@XmlElement
@XmlJavaTypeAdapter(PathAdapter.class)
private final Path publicKeyPath;

@ValidContent(minLines = 1,message = "file expected to contain at least one line")
@NotNull
@ValidPath(checkExists = true, message = "File does not exist")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

import static com.quorum.tessera.config.PrivateKeyType.UNLOCKED;
import com.quorum.tessera.encryption.PrivateKey;
import javax.validation.constraints.Size;

@ValidInlineKeypair
public class InlineKeypair implements ConfigKeyPair {

@Size(min = 1)
@NotNull
@ValidBase64(message = "Invalid Base64 key provided")
@XmlElement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.quorum.tessera.config.constraints;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.UUID;
import javax.validation.ConstraintValidatorContext;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ValidContentValidatorTest {

@Test
public void ignoreNullPath() {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

assertThat(validator.isValid(null, context)).isTrue();

}

@Test
public void ignoreNonExistPath() {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Paths.get(UUID.randomUUID().toString());

assertThat(path).doesNotExist();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void defaultValuesIgnoreEmptyFile() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void expectSingleLineButFileIsEmpty() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}

@Test
public void expectSingleLineFileIsValid() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, "SOMEDATA".getBytes());

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isTrue();

}

@Test
public void tooManyLines() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, Arrays.asList("SOMEDATA","SOMEMOREDATA"));

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}

@Test
public void emptyLine() throws Exception {
ValidContentValidator validator = new ValidContentValidator();
ValidContent validContent = mock(ValidContent.class);
when(validContent.minLines()).thenReturn(1);
when(validContent.maxLines()).thenReturn(1);

validator.initialize(validContent);

final ConstraintValidatorContext context = mock(ConstraintValidatorContext.class);

Path path = Files.createTempFile(UUID.randomUUID().toString(), "");
Files.write(path, Arrays.asList(""));

assertThat(path).exists();

assertThat(validator.isValid(path, context)).isFalse();

}


}
2 changes: 1 addition & 1 deletion data-migration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@
</build>


</project>
</project>
2 changes: 1 addition & 1 deletion encryption/encryption-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
<version>0.8-SNAPSHOT</version>
</parent>

</project>
</project>
2 changes: 1 addition & 1 deletion encryption/encryption-jnacl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@
</profile>
</profiles>

</project>
</project>
2 changes: 1 addition & 1 deletion encryption/encryption-kalium/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
</profile>
</profiles>

</project>
</project>
Loading

0 comments on commit 1b8fc88

Please sign in to comment.