Validate project-id returned from metadata server#2822
Validate project-id returned from metadata server#2822yihanzhen merged 8 commits intogoogleapis:masterfrom
Conversation
which a descriptive failure html page is returned instead of the projectid itself from server when projects are not running in google cloud machines.
| * Returns true if the projectId is valid. | ||
| * projectId must be between 6 and 30 characters | ||
| * projectId can have lowercase letters, digits or hyphens | ||
| * and must start with a lowercase letter |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * and must start with a lowercase letter | ||
| */ | ||
| private boolean isValidProjectId(String projectId) { | ||
| Pattern p = Pattern.compile("^[a-z][a-z0-9-]*$"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * projectId can have lowercase letters, digits or hyphens | ||
| * and must start with a lowercase letter | ||
| */ | ||
| private boolean isValidProjectId(String projectId) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
which a descriptive failure html page is returned instead of the projectid itself from server when projects are not running in google cloud machines.
a934449 to
7ab63f1
Compare
|
PTAL |
| private static final RetrySettings NO_RETRY_SETTINGS = getDefaultRetrySettingsBuilder() | ||
| .setMaxAttempts(1).build(); | ||
|
|
||
| private static final Pattern projectIdPattern = Pattern.compile("^[a-z][a-z0-9-]*[a-z0-9]+$"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| assertThat(ServiceOptions.isValidProjectId(validProjectId)).isTrue(); | ||
| assertThat(ServiceOptions.isValidProjectId(invalidProjectId1)).isFalse(); | ||
| assertThat(ServiceOptions.isValidProjectId(invalidProjectId2)).isFalse(); | ||
| assertThat(ServiceOptions.isValidProjectId(invalidProjectId3)).isFalse(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
PTAL |
wsh
left a comment
There was a problem hiding this comment.
As it is, this change introduces a bug (it will reject project IDs with colons in them). Please consider reverting the merge.
| && !projectId.endsWith("-"); | ||
| } | ||
|
|
||
| private static boolean isLowerCase(char c) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return c >= 'a' && c <= 'z'; | ||
| } | ||
|
|
||
| private static boolean isDigit(char c) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| return false; | ||
| } | ||
| } | ||
| return projectId.length() > 0 && isLowerCase(projectId.charAt(0)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * method is primarily used to protect against DNS hijacking. | ||
| */ | ||
| static boolean isValidProjectId(String projectId) { | ||
| for (char c : projectId.toCharArray()) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Validate project-id returned from metadata server to handle cases in which a descriptive failure html page is returned instead of the project-id itself from server when projects are not running in google cloud machines.