Skip to content

Commit

Permalink
Token validity check added
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Feb 17, 2018
1 parent 5361e9a commit 8da3d46
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class TokenDispenserClient {

static private final String PARAMETER_EMAIL = "email";

static private final int TOKEN_VALIDITY_LENGTH = 100;

private String url;
private HttpClientAdapter httpClient;

Expand Down Expand Up @@ -43,7 +45,14 @@ static private String getUrl(String url, String resource, String email) {

static private String request(HttpClientAdapter httpClient, String url) throws IOException {
try {
return new String(httpClient.get(url));
String response = new String(httpClient.get(url));
if (response.length() > TOKEN_VALIDITY_LENGTH) {
throw new TokenDispenserException("Token is unexpectedly long");
}
if (response.matches(".*[\\r\\n].*")) {
throw new TokenDispenserException("Contains unexpected characters");
}
return response;
} catch (GooglePlayException e) {
switch (e.getCode()) {
case 401:
Expand Down

0 comments on commit 8da3d46

Please sign in to comment.