diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-08-20 07:59:14 +0200 |
---|---|---|
committer | Harald Musum <musum@verizonmedia.com> | 2020-08-20 07:59:14 +0200 |
commit | d78b1abf59d97a271a0e6dbb07c6e460e2e33f7b (patch) | |
tree | 893bedb18dfd0dc0edc7af10c25e72b329253feb /configserver/src | |
parent | 427a8ff09ba630f2f160fb2a3e98bc6fe0fd2efd (diff) |
Throw exception if trying to write application id for another tenant
Diffstat (limited to 'configserver/src')
4 files changed, 42 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java index 10e45d041ec..ee9b8a60305 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/TenantApplications.java @@ -163,6 +163,8 @@ public class TenantApplications implements RequestHandler, HostValidator<Applica * Creates a node for the given application, marking its existence. */ public void createApplication(ApplicationId id) { + if (! id.tenant().equals(tenant)) + throw new IllegalArgumentException("Cannot write application id '" + id + "' for tenant '" + tenant + "'"); try (Lock lock = lock(id)) { curator.create(applicationPath(id)); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java index fc01584cde1..d28a322a05a 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClient.java @@ -142,6 +142,8 @@ public class SessionZooKeeperClient { } public void writeApplicationId(ApplicationId id) { + if ( ! id.tenant().equals(tenantName)) + throw new IllegalArgumentException("Cannot write application id '" + id + "' for tenant '" + tenantName + "'"); configCurator.putData(applicationIdPath(), id.serializedForm()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java index 3aee202e42c..b181ad3e8d6 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionPreparerTest.java @@ -51,6 +51,7 @@ import com.yahoo.vespa.flags.InMemoryFlagSource; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import javax.security.auth.x500.X500Principal; @@ -99,6 +100,9 @@ public class SessionPreparerTest { @Rule public TemporaryFolder folder = new TemporaryFolder(); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Before public void setUp() throws IOException { curator = new MockCurator(); @@ -220,6 +224,20 @@ public class SessionPreparerTest { } @Test + public void require_that_writing_wrong_application_id_fails() throws IOException { + TenantName tenant = TenantName.from("tenant"); + ApplicationId origId = new ApplicationId.Builder() + .tenant(tenant) + .applicationName("foo") + .instanceName("quux") + .build(); + PrepareParams params = new PrepareParams.Builder().applicationId(origId).build(); + expectedException.expect(RuntimeException.class); + expectedException.expectMessage("Error preparing session"); + prepare(testApp, params); + } + + @Test public void require_that_file_reference_of_application_package_is_written_to_zk() throws Exception { flagSource.withBooleanFlag(Flags.CONFIGSERVER_DISTRIBUTE_APPLICATION_PACKAGE.id(), true); prepare(testApp); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java index d6e16cec7e9..de55a6677ff 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/session/SessionZooKeeperClientTest.java @@ -12,7 +12,9 @@ import com.yahoo.vespa.config.util.ConfigUtils; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import java.time.Instant; @@ -30,6 +32,9 @@ public class SessionZooKeeperClientTest { private Curator curator; private ConfigCurator configCurator; + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Before public void setup() { curator = new MockCurator(); @@ -87,6 +92,21 @@ public class SessionZooKeeperClientTest { } @Test + public void require_that_wrong_application_gives_exception() { + ApplicationId id = new ApplicationId.Builder() + .tenant("someOtherTenant") + .applicationName("foo") + .instanceName("bim") + .build(); + int sessionId = 3; + SessionZooKeeperClient zkc = createSessionZKClient(sessionId); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("Cannot write application id 'someOtherTenant.foo.bim' for tenant 'default'"); + zkc.writeApplicationId(id); + } + + @Test public void require_that_application_id_is_read_from_zk() { ApplicationId id = new ApplicationId.Builder() .tenant("tenant") |