Fix time format

This commit is contained in:
Rene Pfeuffer
2019-10-21 10:24:53 +02:00
parent 2a501a9dbb
commit 647464618a
2 changed files with 10 additions and 4 deletions

View File

@@ -5,14 +5,20 @@ import sonia.scm.security.AccessToken;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collections; import java.util.Collections;
import java.util.TimeZone;
class ExpiringAction extends Response.Action {
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static {
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
}
@SuppressWarnings({"squid:S00116"}) @SuppressWarnings({"squid:S00116"})
// This class is used for json serialization, only // This class is used for json serialization, only
class ExpiringAction extends Response.Action {
public final String expires_at; public final String expires_at;
ExpiringAction(String href, AccessToken accessToken) { ExpiringAction(String href, AccessToken accessToken) {
this.expires_at = new SimpleDateFormat("yyyy-MM-dd'T'HH:MM:ss'Z'").format(accessToken.getExpiration()); this.expires_at = DATE_FORMAT.format(accessToken.getExpiration());
this.href = href; this.href = href;
this.header = Collections.singletonMap("Authorization", "Bearer " + accessToken.compact()); this.header = Collections.singletonMap("Authorization", "Bearer " + accessToken.compact());
} }

View File

@@ -79,7 +79,7 @@ class LFSAuthCommandTest {
CommandContext commandContext = createCommandContext(); CommandContext commandContext = createCommandContext();
commandInterpreter.getProtocolHandler().handle(commandContext, createRepositoryContext()); commandInterpreter.getProtocolHandler().handle(commandContext, createRepositoryContext());
assertThat(commandContext.getOutputStream().toString()) assertThat(commandContext.getOutputStream().toString())
.isEqualTo("{\"href\":\"http://example.com/repo/space/X.git/info/lfs/\",\"header\":{\"Authorization\":\"Bearer ACCESS_TOKEN\"},\"expires_at\":\"2007-05-03T12:05:30Z\"}"); .isEqualTo("{\"href\":\"http://example.com/repo/space/X.git/info/lfs/\",\"header\":{\"Authorization\":\"Bearer ACCESS_TOKEN\"},\"expires_at\":\"2007-05-03T10:15:30Z\"}");
} }
private CommandContext createCommandContext() { private CommandContext createCommandContext() {