Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions qa-tests-backend/src/test/groovy/DefaultPoliciesTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DefaultPoliciesTest extends BaseSpecification {
.addLabel("app", "test")
.addPort(80)

static final private List<Deployment> DEPLOYMENTS = [
static final private Map<String, Deployment> DEPLOYMENTS = [
new Deployment()
.setName (NGINX_LATEST)
.setImagePrefetcherAffinity()
Expand Down Expand Up @@ -122,7 +122,7 @@ class DefaultPoliciesTest extends BaseSpecification {
.setImage("registry.redhat.io/redhat/community-operator-index:v4.19")
.addLabel("app", "test")
.setCommand(["sleep", "600"]),
]
].collectEntries { [(it.name): it] }

static final private Integer WAIT_FOR_VIOLATION_TIMEOUT = 300
static final private Integer VIOLATION_CLEARED_TIMEOUT = WAIT_FOR_VIOLATION_TIMEOUT
Expand Down Expand Up @@ -155,7 +155,7 @@ class DefaultPoliciesTest extends BaseSpecification {
assert gcrId != ""

ImageService.clearImageCaches()
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
ImageService.deleteImages(
SearchServiceOuterClass.RawQuery.newBuilder().setQuery("Image:${deployment.getImage()}").build(),
true)
Expand All @@ -164,9 +164,9 @@ class DefaultPoliciesTest extends BaseSpecification {
SearchServiceOuterClass.RawQuery.newBuilder().setQuery("Image:${STRUTS_DEPLOYMENT.getImage()}").build(),
true)

orchestrator.batchCreateDeployments(DEPLOYMENTS)
orchestrator.batchCreateDeployments(DEPLOYMENTS.values())
orchestrator.createService(new Service(STRUTS_DEPLOYMENT))
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
assert Services.waitForDeployment(deployment)
}
Helpers.collectImageScanForDebug(
Expand All @@ -187,7 +187,7 @@ class DefaultPoliciesTest extends BaseSpecification {
}

def cleanupSpec() {
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
orchestrator.deleteDeployment(deployment)
}
assert ImageIntegrationService.deleteImageIntegration(gcrId)
Expand Down Expand Up @@ -426,7 +426,7 @@ class DefaultPoliciesTest extends BaseSpecification {

and:
"The struts deployment details"
Deployment dep = DEPLOYMENTS.find { it.name == STRUTS }
Deployment dep = DEPLOYMENTS[STRUTS]
RiskOuterClass.Risk risk = Services.getDeploymentWithRisk(dep.deploymentUid).risk

expect:
Expand Down
23 changes: 11 additions & 12 deletions qa-tests-backend/src/test/groovy/K8sEventDetectionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import spock.lang.Tag
import spock.lang.Unroll

class K8sEventDetectionTest extends BaseSpecification {
static final private List<Deployment> DEPLOYMENTS = []
static final private Map<String, Deployment> DEPLOYMENTS = [:]

static private registerDeployment(String name, boolean privileged) {
DEPLOYMENTS.add(
new Deployment().setName(name)
def deployment = new Deployment().setName(name)
.setImage(TEST_IMAGE).addLabel("app", name)
.setPrivilegedFlag(privileged)
.setStdin(true)
.setTty(true)
)
DEPLOYMENTS[name] = deployment
return name
}

Expand All @@ -37,8 +36,8 @@ class K8sEventDetectionTest extends BaseSpecification {
static final private String CLONED_KUBECTL_ATTACH_POLICY_NAME = "CLONED: Kubernetes Actions: Attach to Pod"

def setupSpec() {
orchestrator.batchCreateDeployments(DEPLOYMENTS)
for (Deployment deployment : DEPLOYMENTS) {
orchestrator.batchCreateDeployments(DEPLOYMENTS.values())
for (Deployment deployment : DEPLOYMENTS.values()) {
assert Services.waitForDeployment(deployment)
}

Expand Down Expand Up @@ -104,7 +103,7 @@ class K8sEventDetectionTest extends BaseSpecification {
List<String> violatingDeploymentNames, Map<String, String> podNames,
int expectedK8sViolationsCount) {
violatingDeploymentNames.each { String violatingDeploymentName ->
def violatingDeployment = DEPLOYMENTS.find { it.name == violatingDeploymentName }
def violatingDeployment = DEPLOYMENTS[violatingDeploymentName]
assert violatingDeployment
def violations = Services.getViolationsByDeploymentID(
violatingDeployment.deploymentUid, policyName, false, 60)
Expand Down Expand Up @@ -147,7 +146,7 @@ class K8sEventDetectionTest extends BaseSpecification {
continue
}
log.info "Checking that deployment ${deploymentName} does NOT have a violation"
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment
assert Services.checkForNoViolationsByDeploymentID(deployment.deploymentUid, policyName)
}
Expand Down Expand Up @@ -183,7 +182,7 @@ class K8sEventDetectionTest extends BaseSpecification {
def podNames = new HashMap<String, String>()
def execIntoDeployments = []
for (def deploymentName: execIntoDeploymentNames) {
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment
execIntoDeployments.add(deployment)

Expand Down Expand Up @@ -226,7 +225,7 @@ class K8sEventDetectionTest extends BaseSpecification {
"Exec should fail for all violating deployments, but not for the others, and violations should not be updated"
for (def deploymentName: execIntoDeploymentNames) {
def execShouldSucceed = (violatingDeploymentNames.find { it == deploymentName } == null)
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment
assert orchestrator.execInContainer(deployment, "ls -l") == execShouldSucceed
}
Expand Down Expand Up @@ -279,7 +278,7 @@ class K8sEventDetectionTest extends BaseSpecification {
def podNames = new HashMap<String, String>()
def attachToPodsInDeployments = []
for (def deploymentName: attachToDeploymentNames) {
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment
attachToPodsInDeployments.add(deployment)

Expand Down Expand Up @@ -321,7 +320,7 @@ class K8sEventDetectionTest extends BaseSpecification {
then:
"Attach should fail for all violating deployments, but not for the others, and violations should not be updated"
for (def deploymentName: attachToDeploymentNames) {
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment
// these pods/attach events should be blocked by the enforced policy
orchestrator.attachToContainer(deployment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class PolicyConfigurationTest extends BaseSpecification {
static final private List<DeploymentOuterClass.PortConfig.ExposureLevel> EXPOSURE_VALUES =
[DeploymentOuterClass.PortConfig.ExposureLevel.NODE,
DeploymentOuterClass.PortConfig.ExposureLevel.EXTERNAL]
static final private List<Deployment> DEPLOYMENTS = [
static final private Map<String, Deployment> DEPLOYMENTS = [
new Deployment()
.setName(DEPLOYMENTNGINX)
.setImage(TEST_IMAGE)
Expand Down Expand Up @@ -113,7 +113,7 @@ class PolicyConfigurationTest extends BaseSpecification {
.setServiceAccountName(SERVICE_ACCOUNT_NAME)
.setImage("quay.io/rhacs-eng/qa-multi-arch:nginx-1-15-4-alpine")
.setSkipReplicaWait(true),
]
].collectEntries { [(it.name): it] }

static final private Deployment NGINX_WITH_DIGEST = new Deployment()
.setName(NGINX_LATEST_WITH_DIGEST_NAME)
Expand All @@ -132,7 +132,7 @@ class PolicyConfigurationTest extends BaseSpecification {
.setSkipReplicaWait(false)

static final private Service NPSERVICE =
new Service(DEPLOYMENTS.find { it.name == DEPLOYMENTNGINX_NP })
new Service(DEPLOYMENTS[DEPLOYMENTNGINX_NP])
.setType(Service.Type.NODEPORT)

@Shared
Expand All @@ -154,7 +154,7 @@ class PolicyConfigurationTest extends BaseSpecification {
}

def cleanupSpec() {
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
orchestrator.deleteDeployment(deployment)
}
orchestrator.deleteService(NPSERVICE.name, NPSERVICE.namespace)
Expand Down Expand Up @@ -239,7 +239,7 @@ class PolicyConfigurationTest extends BaseSpecification {
// A fresh scan might be required because other tests in the suite could've run a scan on the same image,
// and we don't want those results to taint this test
// TODO: Find a direct way to clear the cache than just forcing a scan
def dep = DEPLOYMENTS.find { it.getName() == depname }
def dep = DEPLOYMENTS[depname]
assert dep != null

log.info "Deleting image ${dep.getImage()} from DB"
Expand Down
17 changes: 9 additions & 8 deletions qa-tests-backend/src/test/groovy/ProcessBaselinesTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProcessBaselinesTest extends BaseSpecification {

static final private Integer RISK_WAIT_TIME = 240

static final private List<Deployment> DEPLOYMENTS =
static final private Map<String, Deployment> DEPLOYMENTS =
[
DEPLOYMENTNGINX,
DEPLOYMENTNGINX_RESOLVE_VIOLATION,
Expand All @@ -64,6 +64,7 @@ class ProcessBaselinesTest extends BaseSpecification {
.setEnv(["CLUSTER_NAME": "main"])
.addLabel("app", "test")
}
.collectEntries { [(it.name): it] }

@Shared
private Policy unauthorizedProcessExecution
Expand All @@ -88,7 +89,7 @@ class ProcessBaselinesTest extends BaseSpecification {
def "Verify processes risk indicators for the given key after lock on #deploymentName"() {
when:
"exec into the container and run a process and wait for lock to kick in"
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment != null
orchestrator.createDeployment(deployment)
assert Services.waitForDeployment(deployment)
Expand Down Expand Up @@ -147,7 +148,7 @@ class ProcessBaselinesTest extends BaseSpecification {
@Tag("BAT")
def "Verify baseline processes for the given key before and after locking "() {
when:
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment != null
String deploymentId = deployment.getDeploymentUid()
// Currently, we always create a deployment where the container name is the same
Expand Down Expand Up @@ -196,7 +197,7 @@ class ProcessBaselinesTest extends BaseSpecification {
*/
when:
"exec into the container after locking baseline and create a baseline violation"
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment != null
orchestrator.createDeployment(deployment)
assert Services.waitForDeployment(deployment)
Expand Down Expand Up @@ -295,7 +296,7 @@ class ProcessBaselinesTest extends BaseSpecification {
when:
"a deployment is deleted"
// Get all baselines for our deployment and assert they exist
def deployment = DEPLOYMENTS.find { it.name == DEPLOYMENTNGINX_DELETE }
def deployment = DEPLOYMENTS[DEPLOYMENTNGINX_DELETE]
assert deployment != null
orchestrator.createDeployment(deployment)
String containerName = deployment.getName()
Expand Down Expand Up @@ -328,7 +329,7 @@ class ProcessBaselinesTest extends BaseSpecification {
*/
when:
"an added process is removed and baseline is locked and the process is run"
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment != null
orchestrator.createDeployment(deployment)
def deploymentId = deployment.deploymentUid
Expand Down Expand Up @@ -387,7 +388,7 @@ class ProcessBaselinesTest extends BaseSpecification {
given:
"a baseline is created"
// Get all baselines for our deployment and assert they exist
def deployment = DEPLOYMENTS.find { it.name == DEPLOYMENTNGINX_DELETE_API }
def deployment = DEPLOYMENTS[DEPLOYMENTNGINX_DELETE_API]
assert deployment != null
orchestrator.createDeployment(deployment)
String containerName = deployment.getName()
Expand Down Expand Up @@ -426,7 +427,7 @@ class ProcessBaselinesTest extends BaseSpecification {
@Tag("BAT")
def "Processes come in after baseline deleted by API for #deploymentName"() {
when:
def deployment = DEPLOYMENTS.find { it.name == deploymentName }
def deployment = DEPLOYMENTS[deploymentName]
assert deployment != null
orchestrator.createDeployment(deployment)
String deploymentId = deployment.getDeploymentUid()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProcessVisualizationReplicaTest extends BaseSpecification {
static final private String APACHEDEPLOYMENT = "apacheserverdeployment"
static final private String MONGODEPLOYMENT = "mongodeployment"

static final private List<Deployment> DEPLOYMENTS = [
static final private Map<String, Deployment> DEPLOYMENTS = [
new Deployment()
.setName (APACHEDEPLOYMENT)
.setReplicas(REPLICACOUNT)
Expand All @@ -24,22 +24,22 @@ class ProcessVisualizationReplicaTest extends BaseSpecification {
.setReplicas(REPLICACOUNT)
.setImage ("quay.io/rhacs-eng/qa-multi-arch:mongodb")
.addLabel ("app", "test" ),
]
].collectEntries { [(it.name): it] }

static final private MAX_SLEEP_TIME = 180000
static final private SLEEP_INCREMENT = 5000

def setupSpec() {
orchestrator.batchCreateDeployments(DEPLOYMENTS)
for (Deployment deployment : DEPLOYMENTS) {
orchestrator.batchCreateDeployments(DEPLOYMENTS.values())
for (Deployment deployment : DEPLOYMENTS.values()) {
assert Services.waitForDeployment(deployment)
}
}
def cleanupSpec() {
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
orchestrator.deleteDeployment(deployment)
}
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
Services.waitForSRDeletion(deployment)
}
}
Expand All @@ -59,7 +59,7 @@ class ProcessVisualizationReplicaTest extends BaseSpecification {
def "Verify process visualization with replicas on #depName"() {
when:
"Get Process IDs running on deployment: #depName"
String uid = DEPLOYMENTS.find { it.name == depName }.deploymentUid
String uid = DEPLOYMENTS[depName].deploymentUid
assert uid != null

// processContainerMap contains a map of process path to a container id for each time that path was executed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProcessVisualizationTest extends BaseSpecification {
// ldconfig process
static final private String LDCONFIG = "/sbin/ldconfig"

static final private List<Deployment> DEPLOYMENTS = [
static final private Map<String, Deployment> DEPLOYMENTS = [
new Deployment()
.setName (NGINXDEPLOYMENT)
.setImage (TEST_IMAGE)
Expand Down Expand Up @@ -66,20 +66,20 @@ class ProcessVisualizationTest extends BaseSpecification {
.setImagePrefetcherAffinity()
.setImage ("quay.io/rhacs-eng/qa-multi-arch:ROX4979")
.addLabel ("app", "test" ),
]
].collectEntries { [(it.name): it] }

static final private MAX_SLEEP_TIME = 240000
static final private SLEEP_INCREMENT = 5000

def setupSpec() {
orchestrator.batchCreateDeployments(DEPLOYMENTS)
for (Deployment deployment : DEPLOYMENTS) {
orchestrator.batchCreateDeployments(DEPLOYMENTS.values())
for (Deployment deployment : DEPLOYMENTS.values()) {
assert Services.waitForDeployment(deployment)
}
}

def cleanupSpec() {
for (Deployment deployment : DEPLOYMENTS) {
for (Deployment deployment : DEPLOYMENTS.values()) {
orchestrator.deleteDeployment(deployment)
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class ProcessVisualizationTest extends BaseSpecification {
def "Verify process visualization on default: #depName"() {
when:
"Get Process IDs running on deployment: #depName"
String uid = DEPLOYMENTS.find { it.name == depName }.deploymentUid
String uid = DEPLOYMENTS[depName].deploymentUid
assert uid != null

Set<String> receivedProcessPaths
Expand Down Expand Up @@ -193,7 +193,7 @@ class ProcessVisualizationTest extends BaseSpecification {
def "Verify process paths, UIDs, and GIDs on #depName"() {
when:
"Get Processes running on deployment: #depName"
String uid = DEPLOYMENTS.find { it.name == depName }.deploymentUid
String uid = DEPLOYMENTS[depName].deploymentUid
assert uid != null

Map<String,Set<Tuple2<Integer,Integer>>> processToUserAndGroupIds
Expand Down Expand Up @@ -272,7 +272,7 @@ class ProcessVisualizationTest extends BaseSpecification {
def "Verify process arguments on #depName"() {
when:
"Get Process args running on deployment: #depName"
String depId = DEPLOYMENTS.find { it.name == depName }.deploymentUid
String depId = DEPLOYMENTS[depName].deploymentUid
assert depId != null

List<Tuple2<String, String>> processToArgs
Expand Down
Loading
Loading