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
1 change: 0 additions & 1 deletion at_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ The library currently depends on the following

* Bouncycastle
* Jackson
* Apache Commons (will be removed)
* Pico CLI

## Developer Instructions
Expand Down
23 changes: 11 additions & 12 deletions at_client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
Expand All @@ -110,25 +109,24 @@
<artifactId>bcprov-jdk15to18</artifactId>
</dependency>

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

<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -145,7 +143,7 @@
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -163,6 +161,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
4 changes: 2 additions & 2 deletions at_client/src/main/java/org/atsign/client/cli/Scan.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Scanner;
import java.util.concurrent.ExecutionException;

import org.apache.commons.lang3.StringUtils;
import org.atsign.client.api.AtClient;
import org.atsign.client.api.Secondary;
import org.atsign.client.util.ArgsUtil;
import org.atsign.client.util.KeysUtil;
import org.atsign.client.util.StringUtil;
import org.atsign.common.AtException;
import org.atsign.common.AtSign;
import org.atsign.common.Keys.AtKey;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static void main(String[] args) {
// _printAtKeys(atKeys);
System.out.println("Enter index you want to llookup (l to list, q to quit):");
input = scanner.nextLine();
if (StringUtils.isNumeric(input)) {
if (StringUtil.isNumeric(input)) {
int index = Integer.parseInt(input);
if (index < atKeys.size()) {
AtKey atKey = atKeys.get(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void validateMetadata(Metadata metadata) throws AtException {

// validate ttr
if (metadata.ttr == null || metadata.ttr < -1) {
throw new AtInvalidAtKeyException("ttb cannot be null and cannot be < -1");
throw new AtInvalidAtKeyException("ttr cannot be null and cannot be < -1");
}

}
Expand Down
15 changes: 15 additions & 0 deletions at_client/src/main/java/org/atsign/client/util/StringUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.atsign.client.util;

// enables removal of commons-lang
// TODO: review after JDK upgrade
public class StringUtil {

public static boolean isBlank(String s) {
return s == null || s.trim().isEmpty();
}

public static boolean isNumeric(String s) {
return s.matches("\\d+");
}

}
20 changes: 10 additions & 10 deletions at_client/src/main/java/org/atsign/common/VerbBuilders.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.atsign.common;

import org.apache.commons.lang3.StringUtils;
import org.atsign.common.Keys.AtKey;
import org.atsign.common.Keys.PublicKey;
import org.atsign.common.Keys.SharedKey;

import static org.atsign.client.util.StringUtil.isBlank;

/**
*
* Contains builders that build commands that are accepted by a secondary server
Expand Down Expand Up @@ -575,11 +576,11 @@ public String build() {
command += ":showHidden:true";
}

if (fromAtSign != null && !StringUtils.isBlank(fromAtSign)) {
if (fromAtSign != null && !isBlank(fromAtSign)) {
command += ":" + fromAtSign;
}

if (regex != null && !StringUtils.isBlank(regex)) {
if (regex != null && !isBlank(regex)) {
command += " " + regex;
}

Expand Down Expand Up @@ -674,7 +675,7 @@ public void setTtr(long ttr) {
//notify:((?<operation>update|delete):)?(messageType:(?<messageType>key|text):)?(priority:(?<priority>low|medium|high):)?(strategy:(?<strategy>all|latest):)?(latestN:(?<latestN>\d+):)?(notifier:(?<notifier>[^\s:]+):)?(ttln:(?<ttln>\d+):)?(ttl:(?<ttl>\d+):)?(ttb:(?<ttb>\d+):)?(ttr:(?<ttr>(-)?\d+):)?(ccd:(?<ccd>true|false):)?(@(?<forAtSign>[^@:\s]*)):(?<atKey>[^:@]((?!:{2})[^@])+)(@(?<atSign>[^@:\s]+))?(:(?<value>.+))?$
public String build() {

if (key == null || StringUtils.isBlank(key)) {
if (key == null || isBlank(key)) {
throw new IllegalArgumentException("key cannot be null or empty");
}

Expand All @@ -687,7 +688,7 @@ public String build() {
throw new IllegalArgumentException("Invalid value for ttr. Only -1 and positive numbers are allowed");
}

if (ttr != defaultTTRValue && (value == null || StringUtils.isBlank(value))) {
if (ttr != defaultTTRValue && (value == null || isBlank(value))) {
throw new IllegalArgumentException("When the ttr is specified value cannot be null or empty");
}

Expand All @@ -699,7 +700,7 @@ public String build() {
}

// append recipients @sign if it is not part of the key already
if (recipientAtSign != null && !StringUtils.isBlank(recipientAtSign)) {
if (recipientAtSign != null && !isBlank(recipientAtSign)) {

if (!recipientAtSign.startsWith("@")) {
recipientAtSign = "@" + recipientAtSign;
Expand All @@ -711,7 +712,7 @@ public String build() {
// append the key
command += key;

if (senderAtSign != null && !StringUtils.isBlank(senderAtSign)) {
if (senderAtSign != null && !isBlank(senderAtSign)) {

if (!senderAtSign.startsWith("@")) {
senderAtSign = "@" + senderAtSign;
Expand All @@ -720,7 +721,7 @@ public String build() {
command += senderAtSign;
}

if (value != null && !StringUtils.isBlank(value)) {
if (value != null && !isBlank(value)) {
command += ":" + value;
}

Expand All @@ -739,12 +740,11 @@ public void setNotificationId(String notificationId) {
//notify:status:(?<notificationId>\S+)$';
public String build() {

if (notificationId == null || StringUtils.isBlank(notificationId)) {
if (notificationId == null || isBlank(notificationId)) {
throw new IllegalArgumentException("notificationId cannot be null or empty");
}

return "notify:status:" + notificationId;
}
}

}
153 changes: 153 additions & 0 deletions at_client/src/test/java/org/atsign/common/AtClientValidationIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package org.atsign.common;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.atsign.client.util.AtClientValidation;
import org.atsign.common.Keys.PublicKey;
import org.atsign.common.Keys.SelfKey;
import org.atsign.common.Keys.SharedKey;
import org.atsign.cucumber.helpers.Helpers;
import org.atsign.virtualenv.VirtualEnv;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class AtClientValidationIT {

private static final String VE_ROOT_URL = "vip.ve.atsign.zone:64"; // prod rootUrl

@BeforeAll
public static void classSetup() {
if (!Helpers.isHostPortReachable(VE_ROOT_URL, SECONDS.toMillis(2))) {
VirtualEnv.setUp();
}
}

// atSign exists (uses secondaryaddress.finder)
@Test
public void atSignExistsTest() {

// null atSign
assertThrows(AtException.class, () -> {
AtSign atSign = null;
AtClientValidation.atSignExists(atSign, VE_ROOT_URL);
});

// empty atSign
assertThrows(IllegalArgumentException.class, () -> {
AtSign atSign = new AtSign("");
AtClientValidation.atSignExists(atSign, VE_ROOT_URL);
});

// root does not contain atSign
assertThrows(AtException.class, () -> {
AtSign atSign = new AtSign("someAtSignThatDNE456");
AtClientValidation.atSignExists(atSign, VE_ROOT_URL);
});

// invalid root
assertThrows(AtException.class, () -> {
AtSign atSign = new AtSign("smoothalligator");
AtClientValidation.atSignExists(atSign, "invalidroot:32123");
});

}

// validate AtKey object is ready (checks atKey.name validity, metadata
// validity, and if sharedWith exists)
@Test
public void validateAtKeyTest() {

// ====================================
// PublicKey tests
// ====================================

// null publicKey
assertThrows(AtException.class, () -> {
PublicKey publicKey = null;
AtClientValidation.validateAtKey(publicKey, VE_ROOT_URL);
});

// public key with invalid ttr
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@bob");
PublicKey publicKey = new KeyBuilders.PublicKeyBuilder(sharedBy).key("test").build();
publicKey.metadata.ttr = -2;
AtClientValidation.validateAtKey(publicKey, "");
});

// ====================================
// SelfKey tests
// ====================================

// null selfKey
assertThrows(AtException.class, () -> {
SelfKey selfKey = null;
AtClientValidation.validateAtKey(selfKey, VE_ROOT_URL);
});

// self key with invalid keyName
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@bob");
SelfKey selfKey = new KeyBuilders.SelfKeyBuilder(sharedBy).key("t est").build();
AtClientValidation.validateAtKey(selfKey, VE_ROOT_URL);
});

// self key with non-existent sharedWith atSign in root
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@nonexistentatsign");
AtSign sharedWith = new AtSign("@nonexistentatsign"); // atSign does not exist in root
SelfKey selfKey = new KeyBuilders.SelfKeyBuilder(sharedBy, sharedWith).key("test").build();
AtClientValidation.validateAtKey(selfKey, VE_ROOT_URL);
});

// ====================================
// SharedKey tests
// ====================================

// null shared key test
assertThrows(AtException.class, () -> {
SharedKey sharedKey = null;
AtClientValidation.validateAtKey(sharedKey, VE_ROOT_URL);
});

// shared key with ttr < -1
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@bob");
AtSign sharedWith = new AtSign("@alice");
SharedKey sharedKey = new KeyBuilders.SharedKeyBuilder(sharedBy, sharedWith).key("test").build();
sharedKey.metadata.ttr = -22323;
AtClientValidation.validateAtKey(sharedKey, VE_ROOT_URL);
});

// shared key with invalid keyName
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@bob");
AtSign sharedWith = new AtSign("@alice");
SharedKey sharedKey = new KeyBuilders.SharedKeyBuilder(sharedBy, sharedWith).key("t est").build();
AtClientValidation.validateAtKey(sharedKey, VE_ROOT_URL);
});

// shared key with invalid sharedWith atSign (atSign dne in root)
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@wildgreen");
AtSign sharedWith = new AtSign("@nonexistentatsign"); // atSign does not exist in root
SharedKey sharedKey = new KeyBuilders.SharedKeyBuilder(sharedBy, sharedWith).key("test").build();
AtClientValidation.validateAtKey(sharedKey, VE_ROOT_URL);
});

// empty root url
assertThrows(AtException.class, () -> {
AtSign sharedBy = new AtSign("@bob");
AtSign sharedWith = new AtSign("@alice");
SharedKey sharedKey = new KeyBuilders.SharedKeyBuilder(sharedBy, sharedWith).key("test").build();
AtClientValidation.validateAtKey(sharedKey, "");
});

// ====================================
// PrivateHiddenKey tests
// ====================================

// TODO
}
}
Loading
Loading