Skip to content

Commit

Permalink
Merge pull request #897 from Microsoft/feature/userid-invalid-prefix
Browse files Browse the repository at this point in the history
Improve error message when 1DS userId has only an invalid prefix and nothing after the prefix
  • Loading branch information
dhei committed Nov 28, 2018
2 parents 73407f0 + ba9b0b3 commit f421f75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -58,16 +58,19 @@ public static boolean checkUserIdValidForOneCollector(String userId) {
if (userId == null) {
return true;
}
int prefixIndex = userId.indexOf(COMMON_SCHEMA_PREFIX_SEPARATOR);
if (prefixIndex == userId.length() - 1) {
if (userId.isEmpty()) {
AppCenterLog.error(LOG_TAG, "userId must not be empty.");
return false;
}
int prefixIndex = userId.indexOf(COMMON_SCHEMA_PREFIX_SEPARATOR);
if (prefixIndex >= 0) {
String prefix = userId.substring(0, prefixIndex);
if (!prefix.equals(CUSTOM_PREFIX)) {
AppCenterLog.error(LOG_TAG, String.format("userId prefix must be '%s%s', '%s%s' is not supported.", CUSTOM_PREFIX, COMMON_SCHEMA_PREFIX_SEPARATOR, prefix, COMMON_SCHEMA_PREFIX_SEPARATOR));
return false;
} else if (prefixIndex == userId.length() - 1) {
AppCenterLog.error(LOG_TAG, "userId must not be empty.");
return false;
}
}
return true;
Expand Down
Expand Up @@ -14,6 +14,7 @@ public void userIdInvalidForOneCollector() {
assertFalse(UserIdContext.checkUserIdValidForOneCollector(""));
assertFalse(UserIdContext.checkUserIdValidForOneCollector(":alice"));
assertFalse(UserIdContext.checkUserIdValidForOneCollector("c:"));
assertFalse(UserIdContext.checkUserIdValidForOneCollector("x:"));
assertFalse(UserIdContext.checkUserIdValidForOneCollector("x:alice"));
}

Expand Down

0 comments on commit f421f75

Please sign in to comment.