Prevent accidentally using full Drive URL as folder ID (#144)

* Prevent accidentally using full Drive URL as folder ID
This commit is contained in:
Ben McIlwain 2019-07-03 14:22:15 -04:00 committed by GitHub
parent 0ffe7cd5dc
commit 012d9d5893
7 changed files with 14 additions and 4 deletions

View file

@ -868,7 +868,9 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
return this;
}
public Builder setDriveFolderId(String driveFolderId) {
public Builder setDriveFolderId(@Nullable String driveFolderId) {
checkArgument(driveFolderId == null || !driveFolderId.contains("/"),
"Drive folder ID must not be a full URL");
getInstance().driveFolderId = driveFolderId;
return this;
}

View file

@ -237,7 +237,7 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand {
@Nullable
@Parameter(
names = "--drive_folder_id",
description = "Id of this registrar's folder in Drive",
description = "Id (not full URL) of this registrar's folder in Drive",
converter = OptionalStringParameter.class,
validateWith = OptionalStringParameter.class)
Optional<String> driveFolderId;

View file

@ -240,12 +240,12 @@
{param required: true /}
{/call}
{call registry.soy.forms.inputFieldRowWithValue}
{param label: 'DRIVE ID' /}
{param label: 'Drive ID' /}
{param name: 'driveId' /}
{param value: $driveId /}
{param placeholder: 'required' /}
{param description kind="text"}
Id of this registrar's folder in Drive.
ID (not full URL) of this registrar's folder in Google Drive.
{/param}
{param required: true /}
{/call}

View file

@ -452,6 +452,14 @@ public class RegistrarTest extends EntityTestCase {
() -> registrar.asBuilder().setAllowedTldsUncached(ImmutableSet.of("bad")));
}
@Test
public void testFailure_driveFolderId_asFullUrl() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> registrar.asBuilder().setDriveFolderId(
"https://drive.google.com/drive/folders/1j3v7RZkU25DjbTx2-Q93H04zKOBau89M"));
assertThat(thrown).hasMessageThat().isEqualTo("Drive folder ID must not be a full URL");
}
@Test
public void testFailure_nullEmail() {
NullPointerException thrown =

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

After

Width:  |  Height:  |  Size: 86 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Before After
Before After