Skip to content

Commit 2ddaaa5

Browse files
authored
---
yaml --- r: 8971 b: refs/heads/lesv-patch-1 c: 0ca34ad h: refs/heads/master i: 8969: 2e9d678 8967: 215bfbc
1 parent 487b1d7 commit 2ddaaa5

3 files changed

Lines changed: 2 additions & 36 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ refs/tags/v0.22.0: 18b298fe4bfe8ec2f20b0e0bf7ffdcce5cc3c5fe
6666
refs/heads/vam-google-patch-1: d0c8fee3a4074d0bf7360ce8c4f7f7223d0ee7b9
6767
refs/heads/vam-google-patch-CODEOWNERS: 2ac1616e25229e51d08a984708ef1918f91a35ee
6868
refs/heads/danoscarmike-patch-1: 7342a9916bce4ed00002c7202e2a16c5d46afaea
69-
refs/heads/lesv-patch-1: 536af840f93622a8743d7c129104e72909aeab0a
69+
refs/heads/lesv-patch-1: 0ca34ad5460eb92fa426dd0ae6db5a34d8c92e7a
7070
refs/heads/ml-update-branch: 079dd6610017f5c51b9d1938c12d6d55b61513cf
7171
refs/heads/vkedia-patch-2: 7d8241388a9769a5c069334761b06c7012c878e7
7272
refs/heads/vkedia-patch-3: 4d128043acaa7db9160faf439d2ca6104e8a88cb

branches/lesv-patch-1/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,7 @@ private static String getAppEngineProjectIdFromMetadataServer() throws IOExcepti
452452
.setReadTimeout(500)
453453
.setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google"));
454454
HttpResponse response = request.execute();
455-
String projectId = response.parseAsString();
456-
return projectId != null && isValidProjectId(projectId)? projectId : null;
455+
return response.parseAsString();
457456
}
458457

459458
protected static String getServiceAccountProjectId() {
@@ -477,29 +476,6 @@ static String getServiceAccountProjectId(String credentialsPath) {
477476
return project;
478477
}
479478

480-
/*
481-
* Returns true if the projectId is valid. This method checks whether the projectId
482-
* contains only lowercase letters, digits and hyphens, starts with a lowercase letter
483-
* and does not end with a hyphen, but does not check the length of projectId. This
484-
* method is primarily used to protect against DNS hijacking.
485-
*/
486-
static boolean isValidProjectId(String projectId) {
487-
for (char c : projectId.toCharArray()) {
488-
if (!isLowerCase(c) && !isDigit(c) && c != '-') {
489-
return false;
490-
}
491-
}
492-
return projectId.length() > 0 && isLowerCase(projectId.charAt(0))
493-
&& !projectId.endsWith("-");
494-
}
495-
496-
private static boolean isLowerCase(char c) {
497-
return c >= 'a' && c <= 'z';
498-
}
499-
500-
private static boolean isDigit(char c) {
501-
return c >= '0' && c <= '9';
502-
}
503479

504480
/**
505481
* Returns a Service object for the current service. For instance, when using Google Cloud

branches/lesv-patch-1/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import static org.junit.Assert.assertSame;
2424
import static org.junit.Assert.assertTrue;
2525
import static org.junit.Assert.fail;
26-
import static com.google.common.truth.Truth.assertThat;
2726

2827
import com.google.api.core.ApiClock;
2928
import com.google.api.core.CurrentMillisClock;
@@ -314,13 +313,4 @@ public void testGetServiceAccountProjectId_nonExistentFile() throws Exception {
314313

315314
assertNull(ServiceOptions.getServiceAccountProjectId(credentialsFile.getPath()));
316315
}
317-
318-
@Test
319-
public void testValidateProjectId() throws Exception {
320-
assertThat(ServiceOptions.isValidProjectId("abc-123")).isTrue();
321-
assertThat(ServiceOptions.isValidProjectId("abc-123-ab")).isTrue();
322-
assertThat(ServiceOptions.isValidProjectId("abc=123")).isFalse();
323-
assertThat(ServiceOptions.isValidProjectId("abc123-")).isFalse();
324-
assertThat(ServiceOptions.isValidProjectId("1abc-23")).isFalse();
325-
}
326316
}

0 commit comments

Comments
 (0)