Merge "Add @Sandboxed annotation for classes and methods"

This commit is contained in:
David Pursehouse 2016-09-23 07:14:40 +00:00 committed by Gerrit Code Review
commit 2605c4c9a6
4 changed files with 75 additions and 5 deletions

View File

@ -353,7 +353,8 @@ public abstract class AbstractDaemonTest {
baseConfig.setString("gerrit", null, "tempSiteDir",
tempSiteDir.getRoot().getPath());
baseConfig.setInt("receive", null, "changeUpdateThreads", 4);
if (classDesc.equals(methodDesc)) {
if (classDesc.equals(methodDesc) && !classDesc.sandboxed() &&
!methodDesc.sandboxed()) {
if (commonServer == null) {
commonServer = GerritServer.start(classDesc, baseConfig);
}

View File

@ -61,7 +61,8 @@ public class GerritServer {
return new AutoValue_GerritServer_Description(
configName,
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); // @GerritConfigs is only valid on methods.
@ -73,14 +74,16 @@ public class GerritServer {
configName,
testDesc.getAnnotation(UseLocalDisk.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(GerritConfigs.class));
}
private static boolean hasNoHttpd(Class<?> clazz) {
private static boolean has(Class annotation, Class<?> clazz) {
for (; clazz != null; clazz = clazz.getSuperclass()) {
if (clazz.getAnnotation(NoHttpd.class) != null) {
if (clazz.getAnnotation(annotation) != null) {
return true;
}
}
@ -90,6 +93,7 @@ public class GerritServer {
@Nullable abstract String configName();
abstract boolean memory();
abstract boolean httpd();
abstract boolean sandboxed();
@Nullable abstract GerritConfig config();
@Nullable abstract GerritConfigs configs();

View File

@ -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 {
}

View File

@ -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();
}
}