Merge "Add @Sandboxed annotation for classes and methods"
This commit is contained in:
@@ -353,7 +353,8 @@ public abstract class AbstractDaemonTest {
|
|||||||
baseConfig.setString("gerrit", null, "tempSiteDir",
|
baseConfig.setString("gerrit", null, "tempSiteDir",
|
||||||
tempSiteDir.getRoot().getPath());
|
tempSiteDir.getRoot().getPath());
|
||||||
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
|
||||||
if (classDesc.equals(methodDesc)) {
|
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() &&
|
||||||
|
!methodDesc.sandboxed()) {
|
||||||
if (commonServer == null) {
|
if (commonServer == null) {
|
||||||
commonServer = GerritServer.start(classDesc, baseConfig);
|
commonServer = GerritServer.start(classDesc, baseConfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ public class GerritServer {
|
|||||||
return new AutoValue_GerritServer_Description(
|
return new AutoValue_GerritServer_Description(
|
||||||
configName,
|
configName,
|
||||||
true, // @UseLocalDisk is only valid on methods.
|
true, // @UseLocalDisk is only valid on methods.
|
||||||
!hasNoHttpd(testDesc.getTestClass()),
|
!has(NoHttpd.class, testDesc.getTestClass()),
|
||||||
|
has(Sandboxed.class, testDesc.getTestClass()),
|
||||||
null, // @GerritConfig is only valid on methods.
|
null, // @GerritConfig is only valid on methods.
|
||||||
null); // @GerritConfigs is only valid on methods.
|
null); // @GerritConfigs is only valid on methods.
|
||||||
|
|
||||||
@@ -73,14 +74,16 @@ public class GerritServer {
|
|||||||
configName,
|
configName,
|
||||||
testDesc.getAnnotation(UseLocalDisk.class) == null,
|
testDesc.getAnnotation(UseLocalDisk.class) == null,
|
||||||
testDesc.getAnnotation(NoHttpd.class) == null
|
testDesc.getAnnotation(NoHttpd.class) == null
|
||||||
&& !hasNoHttpd(testDesc.getTestClass()),
|
&& !has(NoHttpd.class, testDesc.getTestClass()),
|
||||||
|
testDesc.getAnnotation(Sandboxed.class) != null ||
|
||||||
|
has(Sandboxed.class, testDesc.getTestClass()),
|
||||||
testDesc.getAnnotation(GerritConfig.class),
|
testDesc.getAnnotation(GerritConfig.class),
|
||||||
testDesc.getAnnotation(GerritConfigs.class));
|
testDesc.getAnnotation(GerritConfigs.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasNoHttpd(Class<?> clazz) {
|
private static boolean has(Class annotation, Class<?> clazz) {
|
||||||
for (; clazz != null; clazz = clazz.getSuperclass()) {
|
for (; clazz != null; clazz = clazz.getSuperclass()) {
|
||||||
if (clazz.getAnnotation(NoHttpd.class) != null) {
|
if (clazz.getAnnotation(annotation) != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +93,7 @@ public class GerritServer {
|
|||||||
@Nullable abstract String configName();
|
@Nullable abstract String configName();
|
||||||
abstract boolean memory();
|
abstract boolean memory();
|
||||||
abstract boolean httpd();
|
abstract boolean httpd();
|
||||||
|
abstract boolean sandboxed();
|
||||||
@Nullable abstract GerritConfig config();
|
@Nullable abstract GerritConfig config();
|
||||||
@Nullable abstract GerritConfigs configs();
|
@Nullable abstract GerritConfigs configs();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Copyright (C) 2016 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.acceptance;
|
||||||
|
|
||||||
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
|
import static java.lang.annotation.ElementType.TYPE;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({TYPE, METHOD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface Sandboxed {
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (C) 2016 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package com.google.gerrit.acceptance;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@Sandboxed
|
||||||
|
public class SandboxTest extends AbstractDaemonTest {
|
||||||
|
@After
|
||||||
|
public void addUser() throws Exception {
|
||||||
|
gApi.accounts().create("sandboxuser");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUserNotPresent1() throws Exception {
|
||||||
|
assertThat(gApi.accounts().query("sandboxuser").get()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUserNotPresent2() throws Exception {
|
||||||
|
assertThat(gApi.accounts().query("sandboxuser").get()).isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user