Skip to content

Commit 1df301d

Browse files
jkuaaronlew02
authored andcommitted
tuf-cli: use "date" directly to get current time
the shell script runs under faketime in the test suite so we can just get current time without dealing with faketime env vars. The java code is a bit simpler since it can just assume the time is set. Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent 981e60a commit 1df301d

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

tuf-cli/src/main/java/dev/sigstore/tuf/cli/TufConformanceServer.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,8 @@ private static void handleExecute(HttpServletRequest request, HttpServletRespons
8989
System.setOut(outPs);
9090
System.setErr(errPs);
9191

92-
if (executeRequest.faketime != null && !executeRequest.faketime.isEmpty()) {
93-
String faketime = executeRequest.faketime;
94-
Instant fakeNow;
95-
try {
96-
long offsetSeconds = Long.parseLong(faketime);
97-
fakeNow = Instant.now().plusSeconds(offsetSeconds);
98-
} catch (NumberFormatException e) {
99-
throw new IOException(
100-
"Faketime must be a relative offset in seconds (e.g., '+3600' or '-3600'), but was: "
101-
+ faketime,
102-
e);
103-
}
104-
TestClock.set(Clock.fixed(fakeNow, ZoneOffset.UTC));
105-
}
92+
Instant fakeNow = Instant.ofEpochSecond(Long.parseLong(executeRequest.faketime));
93+
TestClock.set(Clock.fixed(fakeNow, ZoneOffset.UTC));
10694

10795
List<String> resolvedArgs = new java.util.ArrayList<>();
10896
resolvedArgs.addAll(Arrays.asList(executeRequest.args));

tuf-cli/tuf-cli-server

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ if [[ $ARGS_JSON == *, ]]; then
1414
fi
1515
ARGS_JSON="$ARGS_JSON]"
1616

17-
FAKETIME_VAL="${FAKETIME:-}"
17+
DATE_VAL="$(date +%s)"
1818

19-
JSON_PAYLOAD=$(jq -nc --arg cwd "$CWD" --argjson args "$ARGS_JSON" --arg faketime "$FAKETIME_VAL" '{"cwd": $cwd, "args": $args, "faketime": $faketime}')
19+
JSON_PAYLOAD=$(jq -nc --arg cwd "$CWD" --argjson args "$ARGS_JSON" --arg faketime "$DATE_VAL" '{"cwd": $cwd, "args": $args, "faketime": $faketime}')
2020

2121
RESPONSE=$(curl -s -X POST --header "Content-Type: application/json" --data-binary "$JSON_PAYLOAD" http://localhost:8080/execute)
2222

0 commit comments

Comments
 (0)