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
4 changes: 2 additions & 2 deletions components/policies/PolicyAssignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ const PolicyAssignments = ({ policy }) => {
return (
<div className={styles[theme]}>
<Loading loading={loading}>
{data && data?.policyAssignments?.length > 0 ? (
{data && data?.data?.length > 0 ? (
<>
{data.policyAssignments.map((assignment) => {
{data.data.map((assignment) => {
return (
<div key={assignment.id} className={styles.assignmentCard}>
<div>
Expand Down
26 changes: 24 additions & 2 deletions cypress/fixtures/policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,32 @@
"Existing": {
"data": [
{
"id": "12345678910",
"id": "34912489-bd2a-409e-a00a-da274aff0635",
"policyId": "34912489-bd2a-409e-a00a-da274aff0635",
"name": "My Policy Name",
"description": "This is a policy description",
"regoContent": "package RegoRegoRego"
"regoContent": "package RegoRegoRego",
"currentVersion": 2,
"policyVersionId": "34912489-bd2a-409e-a00a-da274aff0635.1"
}
],
"versions": [
{
"created": "2021-07-06T13:53:41.872378726Z",
"id": "34912489-bd2a-409e-a00a-da274aff0635.1",
"message": "Initial policy creation",
"regoContent": "package rode.demo.sonar\n\npass {\n\tcount(violation_count) == 0\n}\n\nviolation_count[v] {\n\tviolations[v].pass == false\n}\n\nsonar_scan_started[o] {\n\tstartswith(input.occurrences[i].noteName, \"projects/rode/notes/sonar-scan\")\n\tinput.occurrences[i].kind == \"DISCOVERY\"\n\tinput.occurrences[i].discovered.discovered.analysisStatus == \"SCANNING\"\n\to := input.occurrences[i]\n}\n\nsonar_scan_finished[t] {\n\tstartswith(input.occurrences[i].noteName, \"projects/rode/notes/sonar-scan\")\n\tinput.occurrences[i].kind == \"DISCOVERY\"\n\tinput.occurrences[i].discovered.discovered.analysisStatus == \"FINISHED_SUCCESS\"\n\tt := input.occurrences[i].createTime\n}\n\nviolations[result] {\n\tstarted := sonar_scan_started\n\tresult := {\n\t\t\"pass\": count(started) >= 1,\n\t\t\"id\": \"sonar_scan_started\",\n\t\t\"name\": \"SonarQube Analysis Started\",\n\t\t\"description\": \"Verify SonarQube analysis started\",\n\t\t\"message\": \"SonarQube analysis started\",\n\t}\n}\n\nviolations[result] {\n\tfinished := sonar_scan_finished\n\tresult := {\n\t\t\"pass\": count(finished) >= 1,\n\t\t\"id\": \"sonar_scan_completed\",\n\t\t\"name\": \"SonarQube Analysis Finished\",\n\t\t\"description\": \"Verify SonarQube analysis finished successfully\",\n\t\t\"message\": sprintf(\"SonarQube analysis completed at %v\", [finished]),\n\t}\n}\n",
"sourcePath": "",
"version": 1
}
],
"assignments": [
{
"created": "2021-07-06T13:59:41.639466966Z",
"id": "policies/34912489-bd2a-409e-a00a-da274aff0635/assignments/existing",
"policyGroup": "existing",
"policyVersionId": "34912489-bd2a-409e-a00a-da274aff0635.1",
"updated": "2021-07-06T13:59:41.639466966Z"
}
],
"pageToken": "12345678910pageTokenHere"
Expand Down
48 changes: 48 additions & 0 deletions cypress/fixtures/policy-groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"Existing": {
"data": [
{
"created": "2021-07-06T13:59:28.133457892Z",
"deleted": false,
"description": "policies that limit the number of vulnerabilities",
"name": "existing",
"updated": "2021-07-06T13:59:28.133457892Z"
}
],
"assignments": [],
"pageToken": "12345678910pageTokenHere"
},
"ExistingWithAssignments": {
"data": [
{
"created": "2021-07-06T13:59:28.133457892Z",
"deleted": false,
"description": "policies that limit the number of vulnerabilities",
"name": "existingWithAssignments",
"updated": "2021-07-06T13:59:28.133457892Z"
}
],
"assignments": [
{
"created": "2021-07-06T13:59:41.639466966Z",
"id": "policies/34912489-bd2a-409e-a00a-da274aff0635/assignments/existingWithAssignments",
"policyGroup": "existingWithAssignments",
"policyId": "34912489-bd2a-409e-a00a-da274aff0635",
"policyVersion": 1,
"policyVersionCount": 2,
"policyVersionId": "34912489-bd2a-409e-a00a-da274aff0635.1",
"policyName": "My Policy Name",
"updated": "2021-07-06T13:59:41.639466966Z"
}
],
"pageToken": "12345678910pageTokenHere"
},
"New": {
"data": [
{
"name": "my_brand_new_policy_group",
"description": "This policy group was just created"
}
]
}
}
41 changes: 40 additions & 1 deletion cypress/fixtures/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,46 @@
}
],
"other": []
}
},
"evaluations": [
{
"id": "5e071925-f2d0-489e-8510-52da4dc0b3b6",
"pass": false,
"source": null,
"created": "2021-07-06T18:34:39.733446920Z",
"resourceVersion": {
"version": "harbor.localhost/library/nginx@sha256:0b159cd1ee1203dad901967ac55eee18c24da84ba3be384690304be93538bea8",
"names": ["test", "another tag"],
"created": "2021-07-06T13:58:56.024026238Z"
},
"policyGroup": "vulnerability_limits",
"resourceUri": "harbor.localhost/library/nginx@sha256:0b159cd1ee1203dad901967ac55eee18c24da84ba3be384690304be93538bea8",
"resourceAliases": [
"harbor.localhost/library/nginx:fail-harbor-policy-e6cbe59"
],
"policyEvaluations": [
{
"id": "9f8adc21-7abd-46f8-92f2-e791344b2b9f",
"resourceEvaluationId": "5e071925-f2d0-489e-8510-52da4dc0b3b6",
"pass": false,
"policyVersionId": "923260c9-40e8-4a9a-b41f-547a2e190697.1",
"violations": [
{
"id": "harbor_scan_completed",
"name": "Harbor Scan",
"description": "Verify Harbor image scan completed",
"message": "Harbor scanned image 1 times. Last completed at {'2021-07-06T13:59:21.912469Z'}",
"link": "",
"pass": true
}
],
"policyVersion": 1,
"policyId": "923260c9-40e8-4a9a-b41f-547a2e190697",
"policyName": "Sample Harbor Policy"
}
]
}
]
}
],
"pageToken": "123456789010pagetokenhere"
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/Playground.feature
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Feature: Policy Playground
And I search for "Existing" resource version
And I select "Existing" resource version for evaluation
When the resource <outcome> the policy
Then I see "<message>" message
Then I see the "<message>" message
Scenarios:
| outcome | message |
| passes | SuccessfulEvaluation |
Expand All @@ -29,4 +29,4 @@ Feature: Policy Playground
And I search for "Existing" resource version
And I select "Existing" resource version for evaluation
When I evaluate and an error occurs
Then I see "EvaluationError" message
Then I see the "EvaluationError" message
57 changes: 41 additions & 16 deletions cypress/integration/Policy.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,32 @@ Feature: Policies
Scenario: Search for a non-existent policy
Given I am on the "PolicySearch" page
When I search for a "NonExistent" policy
Then I see "NoPoliciesFound" message
Then I see the "NoPoliciesFound" message

@smoke
@smoke
Scenario: Search for an existing policy
Given I am on the "PolicySearch" page
When I search for an "Existing" policy
Then I see "Existing" policy search result
When I click the "ViewPolicy" button
Then I see "Existing" policy details

@smoke
Scenario: View policy details
Given I am on the "Existing" policy details page
When I select the PolicyDetails Section
Then I see "Existing" policy details

Scenario: View policy version history
Given I am on the "Existing" policy details page
When I select the History Section
Then I see "Existing" policy version history

Scenario: View policy assignments
Given I am on the "Existing" policy details page
When I select the Assignments Section
Then I see "Existing" policy assignment data

@smoke
Scenario: Create policy
Given I open the application
When I navigate to the "CreatePolicy" page
Expand All @@ -29,7 +44,7 @@ Feature: Policies
Scenario: Create policy - require name field
Given I am on the "CreatePolicy" page
When I click the "SavePolicy" button
Then I see "PolicyNameRequired" message
Then I see the "PolicyNameRequired" message
When I type "name" into "PolicyName" input
And I click the "SavePolicy" button
Then I no longer see "PolicyNameRequired" message
Expand All @@ -38,58 +53,68 @@ Feature: Policies
Given I am on the "CreatePolicy" page
When I clear the "PolicyRegoContent" input
When I click the "SavePolicy" button
Then I see "PolicyRegoRequired" message
Then I see the "PolicyRegoRequired" message
When I type "text" into "PolicyRegoContent" input
And I click the "SavePolicy" button
Then I no longer see "PolicyRegoRequired" message

Scenario Outline: Create policy - validating rego code
Given I am on the "CreatePolicy" page
When I test <validity> Rego policy code
Then I see "<message>" message
Then I see the "<message>" message
Scenarios:
| validity | message |
| invalid | PolicyFailedValidation |
| valid | PolicyPassedValidation |
| validity | message |
| invalid | PolicyFailedValidation |
| valid | PolicyPassedValidation |

@updatePolicy
@updatePolicy
Scenario Outline: Edit policy - update fields
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
Then I see the Edit Policy form for "Existing" policy
When I update and save the "Existing" policy <field>
Then I see the updated "Existing" policy <field>
Scenarios:
| field |
| field |
| name |
| description |

Scenario: Edit policy - create new policy version
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
Then I see the Edit Policy form for "Existing" policy
When I update and save the "Existing" policy regoContent
Then I see the "NewPolicyVersion" message
When I type "this is an update message" into "PolicyUpdateMessage" input
And I click the "ConfirmUpdatePolicy" button
Then I see the updated "Existing" policy regoContent

Scenario: Edit policy - invalid rego
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
Then I see the Edit Policy form for "Existing" policy
When I save invalid rego code
Then I see "PolicyFailedUpdateInvalidRego" message
Then I see "PolicyFailedValidation" message
Then I see the "PolicyFailedUpdateInvalidRego" message
Then I see the "PolicyFailedValidation" message

Scenario: Edit policy - unexpected errors
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
And I save the Edit Policy form and an error occurs
Then I see "PolicyFailedUpdate" message
Then I see the "PolicyFailedUpdate" message

Scenario: Delete policy
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
And I click the "DeletePolicy" button
And I confirm to delete the policy
Then I see "DeleteSuccess" message
Then I see the "DeleteSuccess" message

Scenario: Delete policy - unexpected errors
Given I am on the "Existing" policy details page
When I click the "EditPolicy" button
And I click the "DeletePolicy" button
And I confirm to delete the policy and an error occurs
Then I see "PolicyFailedDelete" message
Then I see the "PolicyFailedDelete" message


42 changes: 38 additions & 4 deletions cypress/integration/Policy/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ Given(/^I am on the "([^"]*)" policy details page$/, (policyName) => {
{ url: "**/api/policies/*", method: "GET" },
policies[policyName].data[0]
);

cy.mockRequest(
{ url: "**/api/policies/**/versions*", method: "GET" },
{ data: policies[policyName].versions }
);

cy.mockRequest(
{ url: "**/api/policies/**/assignments*", method: "GET" },
{ data: policies[policyName].assignments }
);
cy.visit(`/policies/${policies[policyName].data[0].id}`);
});

Expand Down Expand Up @@ -82,10 +92,6 @@ When(
const selectorName = `Policy${capitalize(field)}Input`;
cy.get(selectors[selectorName]).clear().type(updatedValues[field]);
cy.get(selectors.UpdatePolicyButton).click();

if (field === "regoContent") {
cy.get(selectors.ConfirmUpdatePolicyButton).click();
}
}
);

Expand Down Expand Up @@ -166,3 +172,31 @@ Then(/^I see the Edit Policy form for "([^"]*)" policy$/, (policyName) => {
cy.get(button).should("be.visible");
});
});

Then(/^I see "([^"]*)" policy version history$/, (policyName) => {
const policyVersion = policies[policyName].versions[0];
cy.url().should("contain", "#history");

cy.get('[data-testid="toggleCard"]')
.click()
.within(() => {
cy.contains("v1 (latest)").should("be.visible");
cy.contains(policyVersion.regoContent).should("be.visible");
});
});

Then(/^I see "([^"]*)" policy assignment data$/, (policyName) => {
const policyAssignment = policies[policyName].assignments[0];
cy.url().should("contain", "#assignments");

cy.contains(policyAssignment.policyGroup).should("be.visible");
cy.contains(policyAssignment.policyVersionId.split(".")[1]).should(
"be.visible"
);
cy.get(selectors.ViewPolicyGroupButton).should("be.visible").click();

cy.url().should(
"match",
new RegExp(`/policy-groups/${policyAssignment.policyGroup}`)
);
});
48 changes: 48 additions & 0 deletions cypress/integration/PolicyGroup.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Feature: Policy Groups

Scenario: Open Policy Group Dashboard
Given I open the application
When I navigate to the "PolicyGroup" page
Then I see the policy groups dashboard

Scenario: Create policy group
Given I open the application
When I navigate to the "PolicyGroup" page
And I click the "CreateNewPolicyGroup" button
Then I see the "CreatePolicyGroup" form
When I create the "New" policy group
Then I see the "New" policy group details

Scenario: Create policy group - invalid name
Given I open the application
When I navigate to the "PolicyGroup" page
And I click the "CreateNewPolicyGroup" button
Then I see the "CreatePolicyGroup" form
When I type "Invalid*Name" into "PolicyGroupName" input
And I click the "SavePolicyGroup" button
Then I see the "InvalidPolicyGroupName" message

@updatePolicyGroup
Scenario: Edit policy group description
Given I am on the Existing policy group details page
When I click the "EditPolicyGroup" button
Then I see the "EditPolicyGroup" form
When I update and save the Existing policy group description
Then I see the updated Existing policy group description

Scenario: Assign policy to policy group
Given I am on the Existing policy group details page
When I click the "EditAssignments" button
Then I see the Edit Existing Assignments page
When I search for an "Existing" policy
And I assign the Existing policy to the Existing policy group
And I click the "SaveAssignments" button
Then I see the Existing policy assigned to the Existing policy group

Scenario: Remove policy from policy group
Given I am on the ExistingWithAssignments policy group details page
When I click the "EditAssignments" button
Then I see the Edit ExistingWithAssignments Assignments page
When I remove an assignment from the ExistingWithAssignments policy group
And I click the "SaveAssignments" button
Then I see no assignments for the ExistingWithAssignments policy group
Loading