diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml new file mode 100644 index 00000000..20990aa2 --- /dev/null +++ b/.github/workflows/artifacts.yml @@ -0,0 +1,69 @@ +name: Artifacts + +on: + pull_request: + branches: [ master, development ] + +jobs: + compile: + name: Cross compile binaries + runs-on: ubuntu-latest + container: + image: golangci/golangci-lint:latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Make repo safe + run: git config --global --add safe.directory /__w/SOARCA/SOARCA + + - name: Install swaggo + run: go install github.com/swaggo/swag/cmd/swag@latest + + - name: Build with make + run: | + go install github.com/swaggo/swag/cmd/swag@latest + go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest + make compile + make sbom + + - name: 'Upload Artifact' + uses: actions/upload-artifact@v4 + with: + name: ${{ github.sha }} + path: bin/* + retention-days: 1 + + docker-build: + needs: compile + name: Build docker image + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Make repo safe + run: git config --global --add safe.directory /__w/SOARCA/SOARCA + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Download bin + uses: actions/download-artifact@v4 + with: + pattern: ${{ github.sha }} + + - name: Move files to bin folder + run: | + mkdir -p bin + mv ${{ github.sha }}/* ./bin/ + + - name: Build image + run: | + export VERSION=$(git describe --tags --dirty) + echo $VERSION + docker build --build-arg VERSION -t $VERSION . \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..306ec83d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: Ci + +on: + pull_request: + branches: [ master, development ] + +jobs: + build: + name: Build binary + runs-on: ubuntu-latest + container: + image: golangci/golangci-lint:latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install swaggo + run: go install github.com/swaggo/swag/cmd/swag@latest + + - name: Build with make + run: make build + + lint: + name: Lint go code with golangci + runs-on: ubuntu-latest + container: + image: golangci/golangci-lint:latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Make repo safe + run: git config --global --add safe.directory /__w/SOARCA/SOARCA + - name: Install swaggo + run: go install github.com/swaggo/swag/cmd/swag@latest + - name: lint + run: | + ls -la + make lint + shell: bash + + test: + name: Run ci-tests + runs-on: ubuntu-latest + container: + image: golang:latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run tests + run: | + apt update + apt install openssh-server -y + useradd sshtest + echo "sshtest:pdKY77qNxpI5MAizirtjCVOcm0KFKIs" | chpasswd + service ssh start + make ci-test + diff --git a/.gitignore b/.gitignore index a1bb9b80..b3652cd1 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ plugins/* build/* !build/build.md bin/* +swaggerdocs/* test/cacao/flatfile-db-example.json test/routes/__debug_bin2988553005 diff --git a/docs/docs.go b/docs/docs.go deleted file mode 100644 index 757e6b8d..00000000 --- a/docs/docs.go +++ /dev/null @@ -1,908 +0,0 @@ -// Package docs Code generated by swaggo/swag. DO NOT EDIT -package docs - -import "github.com/swaggo/swag" - -const docTemplate = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": {}, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/playbook/": { - "get": { - "description": "return all stored playbooks default limit:100", - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "gets all the UUIDs for the stored playbooks", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - } - }, - "post": { - "description": "submit a new playbook api", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "submit playbook via the api", - "parameters": [ - { - "description": "playbook", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - } - }, - "/playbook/meta": { - "get": { - "description": "get playbook meta information for playbook", - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "gets all the meta information for the stored playbooks", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/api.PlaybookMeta" - } - } - } - } - } - }, - "/playbook/{id}": { - "get": { - "description": "get playbook by ID", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "get CACAO playbook by its ID", - "parameters": [ - { - "type": "string", - "description": "playbook ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - }, - "put": { - "description": "update playbook by Id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "update playbook", - "parameters": [ - { - "type": "string", - "description": "playbook Id", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "playbook", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - }, - "delete": { - "description": "delete playbook by Id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "delete playbook by Id", - "parameters": [ - { - "type": "string", - "description": "playbook ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - } - } - } - }, - "/trigger/workflow": { - "post": { - "description": "trigger workflow", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "trigger" - ], - "summary": "trigger a workflow with via cacao payload", - "parameters": [ - { - "description": "execute playbook by payload", - "name": "playbook", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "{\"execution_id\":\"uuid\",\"payload\":\"playbook--uuid\"}" - } - } - } - } - }, - "definitions": { - "api.PlaybookMeta": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - } - } - }, - "cacao.AgentTarget": { - "type": "object", - "required": [ - "name", - "type" - ], - "properties": { - "address": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "agent_target_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "authentication_info": { - "type": "string" - }, - "category": { - "type": "array", - "items": { - "type": "string" - } - }, - "contact": { - "$ref": "#/definitions/cacao.Contact" - }, - "description": { - "type": "string" - }, - "http_url": { - "type": "string" - }, - "id": { - "type": "string" - }, - "location": { - "$ref": "#/definitions/cacao.CivicLocation" - }, - "logical": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "port": { - "type": "string" - }, - "sector": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, - "cacao.AuthenticationInformation": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "kms": { - "type": "boolean" - }, - "kms_key_identifier": { - "type": "string" - }, - "name": { - "type": "string" - }, - "oauth_header": { - "type": "string" - }, - "password": { - "type": "string" - }, - "private_key": { - "type": "string" - }, - "token": { - "type": "string" - }, - "type": { - "type": "string" - }, - "user_id": { - "type": "string" - }, - "username": { - "type": "string" - } - } - }, - "cacao.CivicLocation": { - "type": "object", - "properties": { - "administrative_area": { - "type": "string" - }, - "building_details": { - "type": "string" - }, - "city": { - "type": "string" - }, - "country": { - "type": "string" - }, - "description": { - "type": "string" - }, - "latitude": { - "type": "string" - }, - "longitude": { - "type": "string" - }, - "name": { - "type": "string" - }, - "network_details": { - "type": "string" - }, - "postal_code": { - "type": "string" - }, - "precision": { - "type": "string" - }, - "region": { - "type": "string" - }, - "street_address": { - "type": "string" - } - } - }, - "cacao.Command": { - "type": "object", - "required": [ - "command", - "type" - ], - "properties": { - "command": { - "type": "string" - }, - "command_b64": { - "type": "string" - }, - "content": { - "type": "string" - }, - "content_b64": { - "type": "string" - }, - "description": { - "type": "string" - }, - "headers": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "playbook_activity": { - "type": "string" - }, - "type": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "cacao.Contact": { - "type": "object", - "properties": { - "contact_details": { - "type": "string" - }, - "email": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "phone": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "cacao.DataMarking": { - "type": "object", - "required": [ - "created", - "created_by", - "id", - "type" - ], - "properties": { - "affected_party_notifications": { - "type": "string" - }, - "attribution": { - "type": "string" - }, - "created": { - "type": "string" - }, - "created_by": { - "type": "string" - }, - "description": { - "type": "string" - }, - "encrypt_in_transit": { - "type": "string" - }, - "end_date": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "iep_version": { - "type": "string" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "marking_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "name": { - "type": "string" - }, - "permitted_actions": { - "type": "string" - }, - "revoked": { - "type": "boolean" - }, - "start_date": { - "type": "string" - }, - "statement": { - "type": "string" - }, - "tlp": { - "type": "string" - }, - "tlpv2_level": { - "type": "string" - }, - "type": { - "type": "string" - }, - "unmodified_resale": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - } - } - }, - "cacao.ExtensionDefinition": { - "type": "object", - "required": [ - "created_by", - "schema", - "type", - "version" - ], - "properties": { - "created_by": { - "type": "string" - }, - "description": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "name": { - "type": "string" - }, - "schema": { - "type": "string" - }, - "type": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "cacao.Extensions": { - "type": "object", - "additionalProperties": true - }, - "cacao.ExternalReferences": { - "type": "object", - "required": [ - "description", - "name", - "source", - "url" - ], - "properties": { - "description": { - "type": "string" - }, - "name": { - "type": "string" - }, - "source": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "cacao.Playbook": { - "type": "object", - "required": [ - "created", - "created_by", - "id", - "modified", - "name", - "spec_version", - "type", - "workflow", - "workflow_start" - ], - "properties": { - "agent_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AgentTarget" - } - }, - "authentication_info_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AuthenticationInformation" - } - }, - "created": { - "type": "string" - }, - "created_by": { - "type": "string" - }, - "data_marking_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.DataMarking" - } - }, - "derived_from": { - "type": "array", - "items": { - "type": "string" - } - }, - "description": { - "type": "string" - }, - "extension_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.ExtensionDefinition" - } - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "impact": { - "type": "integer" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "markings": { - "type": "array", - "items": { - "type": "string" - } - }, - "modified": { - "type": "string" - }, - "name": { - "type": "string" - }, - "playbook_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "playbook_types": { - "type": "array", - "items": { - "type": "string" - } - }, - "playbook_variables": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Variable" - } - }, - "priority": { - "type": "integer" - }, - "severity": { - "type": "integer" - }, - "spec_version": { - "type": "string" - }, - "target_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AgentTarget" - } - }, - "type": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - }, - "workflow": { - "$ref": "#/definitions/cacao.Workflow" - }, - "workflow_exception": { - "type": "string" - }, - "workflow_start": { - "type": "string" - } - } - }, - "cacao.Step": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "agent": { - "type": "string" - }, - "authentication_info": { - "type": "string" - }, - "cases": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "commands": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.Command" - } - }, - "condition": { - "type": "string" - }, - "delay": { - "type": "integer" - }, - "description": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "in_args": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "next_steps": { - "type": "array", - "items": { - "type": "string" - } - }, - "on_completion": { - "type": "string" - }, - "on_failure": { - "type": "string" - }, - "on_false": { - "type": "string" - }, - "on_success": { - "type": "string" - }, - "on_true": { - "type": "string" - }, - "out_args": { - "type": "array", - "items": { - "type": "string" - } - }, - "owner": { - "type": "string" - }, - "playbook_id": { - "type": "string" - }, - "playbook_version": { - "type": "string" - }, - "step_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "step_variables": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Variable" - } - }, - "switch": { - "type": "string" - }, - "targets": { - "type": "array", - "items": { - "type": "string" - } - }, - "timeout": { - "type": "integer" - }, - "type": { - "type": "string" - } - } - }, - "cacao.Variable": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "constant": { - "type": "boolean" - }, - "description": { - "type": "string" - }, - "external": { - "type": "boolean" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, - "cacao.Workflow": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Step" - } - } - } -}` - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = &swag.Spec{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", - InfoInstanceName: "swagger", - SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", -} - -func init() { - swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} diff --git a/docs/swagger.json b/docs/swagger.json deleted file mode 100644 index 74f91832..00000000 --- a/docs/swagger.json +++ /dev/null @@ -1,879 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "contact": {} - }, - "paths": { - "/playbook/": { - "get": { - "description": "return all stored playbooks default limit:100", - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "gets all the UUIDs for the stored playbooks", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - } - }, - "post": { - "description": "submit a new playbook api", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "submit playbook via the api", - "parameters": [ - { - "description": "playbook", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - } - }, - "/playbook/meta": { - "get": { - "description": "get playbook meta information for playbook", - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "gets all the meta information for the stored playbooks", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/api.PlaybookMeta" - } - } - } - } - } - }, - "/playbook/{id}": { - "get": { - "description": "get playbook by ID", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "get CACAO playbook by its ID", - "parameters": [ - { - "type": "string", - "description": "playbook ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - }, - "put": { - "description": "update playbook by Id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "update playbook", - "parameters": [ - { - "type": "string", - "description": "playbook Id", - "name": "id", - "in": "path", - "required": true - }, - { - "description": "playbook", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - } - }, - "delete": { - "description": "delete playbook by Id", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "playbook" - ], - "summary": "delete playbook by Id", - "parameters": [ - { - "type": "string", - "description": "playbook ID", - "name": "id", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - } - } - } - }, - "/trigger/workflow": { - "post": { - "description": "trigger workflow", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "trigger" - ], - "summary": "trigger a workflow with via cacao payload", - "parameters": [ - { - "description": "execute playbook by payload", - "name": "playbook", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/cacao.Playbook" - } - } - ], - "responses": { - "200": { - "description": "{\"execution_id\":\"uuid\",\"payload\":\"playbook--uuid\"}" - } - } - } - } - }, - "definitions": { - "api.PlaybookMeta": { - "type": "object", - "properties": { - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - } - } - }, - "cacao.AgentTarget": { - "type": "object", - "required": [ - "name", - "type" - ], - "properties": { - "address": { - "type": "object", - "additionalProperties": { - "type": "array", - "items": { - "type": "string" - } - } - }, - "agent_target_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "authentication_info": { - "type": "string" - }, - "category": { - "type": "array", - "items": { - "type": "string" - } - }, - "contact": { - "$ref": "#/definitions/cacao.Contact" - }, - "description": { - "type": "string" - }, - "http_url": { - "type": "string" - }, - "id": { - "type": "string" - }, - "location": { - "$ref": "#/definitions/cacao.CivicLocation" - }, - "logical": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "port": { - "type": "string" - }, - "sector": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, - "cacao.AuthenticationInformation": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "description": { - "type": "string" - }, - "id": { - "type": "string" - }, - "kms": { - "type": "boolean" - }, - "kms_key_identifier": { - "type": "string" - }, - "name": { - "type": "string" - }, - "oauth_header": { - "type": "string" - }, - "password": { - "type": "string" - }, - "private_key": { - "type": "string" - }, - "token": { - "type": "string" - }, - "type": { - "type": "string" - }, - "user_id": { - "type": "string" - }, - "username": { - "type": "string" - } - } - }, - "cacao.CivicLocation": { - "type": "object", - "properties": { - "administrative_area": { - "type": "string" - }, - "building_details": { - "type": "string" - }, - "city": { - "type": "string" - }, - "country": { - "type": "string" - }, - "description": { - "type": "string" - }, - "latitude": { - "type": "string" - }, - "longitude": { - "type": "string" - }, - "name": { - "type": "string" - }, - "network_details": { - "type": "string" - }, - "postal_code": { - "type": "string" - }, - "precision": { - "type": "string" - }, - "region": { - "type": "string" - }, - "street_address": { - "type": "string" - } - } - }, - "cacao.Command": { - "type": "object", - "required": [ - "command", - "type" - ], - "properties": { - "command": { - "type": "string" - }, - "command_b64": { - "type": "string" - }, - "content": { - "type": "string" - }, - "content_b64": { - "type": "string" - }, - "description": { - "type": "string" - }, - "headers": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "playbook_activity": { - "type": "string" - }, - "type": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "cacao.Contact": { - "type": "object", - "properties": { - "contact_details": { - "type": "string" - }, - "email": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "phone": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - } - }, - "cacao.DataMarking": { - "type": "object", - "required": [ - "created", - "created_by", - "id", - "type" - ], - "properties": { - "affected_party_notifications": { - "type": "string" - }, - "attribution": { - "type": "string" - }, - "created": { - "type": "string" - }, - "created_by": { - "type": "string" - }, - "description": { - "type": "string" - }, - "encrypt_in_transit": { - "type": "string" - }, - "end_date": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "iep_version": { - "type": "string" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "marking_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "name": { - "type": "string" - }, - "permitted_actions": { - "type": "string" - }, - "revoked": { - "type": "boolean" - }, - "start_date": { - "type": "string" - }, - "statement": { - "type": "string" - }, - "tlp": { - "type": "string" - }, - "tlpv2_level": { - "type": "string" - }, - "type": { - "type": "string" - }, - "unmodified_resale": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - } - } - }, - "cacao.ExtensionDefinition": { - "type": "object", - "required": [ - "created_by", - "schema", - "type", - "version" - ], - "properties": { - "created_by": { - "type": "string" - }, - "description": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "name": { - "type": "string" - }, - "schema": { - "type": "string" - }, - "type": { - "type": "string" - }, - "version": { - "type": "string" - } - } - }, - "cacao.Extensions": { - "type": "object", - "additionalProperties": true - }, - "cacao.ExternalReferences": { - "type": "object", - "required": [ - "description", - "name", - "source", - "url" - ], - "properties": { - "description": { - "type": "string" - }, - "name": { - "type": "string" - }, - "source": { - "type": "string" - }, - "url": { - "type": "string" - } - } - }, - "cacao.Playbook": { - "type": "object", - "required": [ - "created", - "created_by", - "id", - "modified", - "name", - "spec_version", - "type", - "workflow", - "workflow_start" - ], - "properties": { - "agent_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AgentTarget" - } - }, - "authentication_info_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AuthenticationInformation" - } - }, - "created": { - "type": "string" - }, - "created_by": { - "type": "string" - }, - "data_marking_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.DataMarking" - } - }, - "derived_from": { - "type": "array", - "items": { - "type": "string" - } - }, - "description": { - "type": "string" - }, - "extension_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.ExtensionDefinition" - } - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "impact": { - "type": "integer" - }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "markings": { - "type": "array", - "items": { - "type": "string" - } - }, - "modified": { - "type": "string" - }, - "name": { - "type": "string" - }, - "playbook_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "playbook_types": { - "type": "array", - "items": { - "type": "string" - } - }, - "playbook_variables": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Variable" - } - }, - "priority": { - "type": "integer" - }, - "severity": { - "type": "integer" - }, - "spec_version": { - "type": "string" - }, - "target_definitions": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.AgentTarget" - } - }, - "type": { - "type": "string" - }, - "valid_from": { - "type": "string" - }, - "valid_until": { - "type": "string" - }, - "workflow": { - "$ref": "#/definitions/cacao.Workflow" - }, - "workflow_exception": { - "type": "string" - }, - "workflow_start": { - "type": "string" - } - } - }, - "cacao.Step": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "agent": { - "type": "string" - }, - "authentication_info": { - "type": "string" - }, - "cases": { - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "commands": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.Command" - } - }, - "condition": { - "type": "string" - }, - "delay": { - "type": "integer" - }, - "description": { - "type": "string" - }, - "external_references": { - "type": "array", - "items": { - "$ref": "#/definitions/cacao.ExternalReferences" - } - }, - "id": { - "type": "string" - }, - "in_args": { - "type": "array", - "items": { - "type": "string" - } - }, - "name": { - "type": "string" - }, - "next_steps": { - "type": "array", - "items": { - "type": "string" - } - }, - "on_completion": { - "type": "string" - }, - "on_failure": { - "type": "string" - }, - "on_false": { - "type": "string" - }, - "on_success": { - "type": "string" - }, - "on_true": { - "type": "string" - }, - "out_args": { - "type": "array", - "items": { - "type": "string" - } - }, - "owner": { - "type": "string" - }, - "playbook_id": { - "type": "string" - }, - "playbook_version": { - "type": "string" - }, - "step_extensions": { - "$ref": "#/definitions/cacao.Extensions" - }, - "step_variables": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Variable" - } - }, - "switch": { - "type": "string" - }, - "targets": { - "type": "array", - "items": { - "type": "string" - } - }, - "timeout": { - "type": "integer" - }, - "type": { - "type": "string" - } - } - }, - "cacao.Variable": { - "type": "object", - "required": [ - "type" - ], - "properties": { - "constant": { - "type": "boolean" - }, - "description": { - "type": "string" - }, - "external": { - "type": "boolean" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - }, - "value": { - "type": "string" - } - } - }, - "cacao.Workflow": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/cacao.Step" - } - } - } -} \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml deleted file mode 100644 index 1f2a72f1..00000000 --- a/docs/swagger.yaml +++ /dev/null @@ -1,585 +0,0 @@ -definitions: - api.PlaybookMeta: - properties: - description: - type: string - id: - type: string - labels: - items: - type: string - type: array - name: - type: string - valid_from: - type: string - valid_until: - type: string - type: object - cacao.AgentTarget: - properties: - address: - additionalProperties: - items: - type: string - type: array - type: object - agent_target_extensions: - $ref: '#/definitions/cacao.Extensions' - authentication_info: - type: string - category: - items: - type: string - type: array - contact: - $ref: '#/definitions/cacao.Contact' - description: - type: string - http_url: - type: string - id: - type: string - location: - $ref: '#/definitions/cacao.CivicLocation' - logical: - items: - type: string - type: array - name: - type: string - port: - type: string - sector: - type: string - type: - type: string - required: - - name - - type - type: object - cacao.AuthenticationInformation: - properties: - description: - type: string - id: - type: string - kms: - type: boolean - kms_key_identifier: - type: string - name: - type: string - oauth_header: - type: string - password: - type: string - private_key: - type: string - token: - type: string - type: - type: string - user_id: - type: string - username: - type: string - required: - - type - type: object - cacao.CivicLocation: - properties: - administrative_area: - type: string - building_details: - type: string - city: - type: string - country: - type: string - description: - type: string - latitude: - type: string - longitude: - type: string - name: - type: string - network_details: - type: string - postal_code: - type: string - precision: - type: string - region: - type: string - street_address: - type: string - type: object - cacao.Command: - properties: - command: - type: string - command_b64: - type: string - content: - type: string - content_b64: - type: string - description: - type: string - headers: - additionalProperties: - type: string - type: object - playbook_activity: - type: string - type: - type: string - version: - type: string - required: - - command - - type - type: object - cacao.Contact: - properties: - contact_details: - type: string - email: - additionalProperties: - type: string - type: object - phone: - additionalProperties: - type: string - type: object - type: object - cacao.DataMarking: - properties: - affected_party_notifications: - type: string - attribution: - type: string - created: - type: string - created_by: - type: string - description: - type: string - encrypt_in_transit: - type: string - end_date: - type: string - external_references: - items: - $ref: '#/definitions/cacao.ExternalReferences' - type: array - id: - type: string - iep_version: - type: string - labels: - items: - type: string - type: array - marking_extensions: - $ref: '#/definitions/cacao.Extensions' - name: - type: string - permitted_actions: - type: string - revoked: - type: boolean - start_date: - type: string - statement: - type: string - tlp: - type: string - tlpv2_level: - type: string - type: - type: string - unmodified_resale: - type: string - valid_from: - type: string - valid_until: - type: string - required: - - created - - created_by - - id - - type - type: object - cacao.ExtensionDefinition: - properties: - created_by: - type: string - description: - type: string - external_references: - items: - $ref: '#/definitions/cacao.ExternalReferences' - type: array - name: - type: string - schema: - type: string - type: - type: string - version: - type: string - required: - - created_by - - schema - - type - - version - type: object - cacao.Extensions: - additionalProperties: true - type: object - cacao.ExternalReferences: - properties: - description: - type: string - name: - type: string - source: - type: string - url: - type: string - required: - - description - - name - - source - - url - type: object - cacao.Playbook: - properties: - agent_definitions: - additionalProperties: - $ref: '#/definitions/cacao.AgentTarget' - type: object - authentication_info_definitions: - additionalProperties: - $ref: '#/definitions/cacao.AuthenticationInformation' - type: object - created: - type: string - created_by: - type: string - data_marking_definitions: - additionalProperties: - $ref: '#/definitions/cacao.DataMarking' - type: object - derived_from: - items: - type: string - type: array - description: - type: string - extension_definitions: - additionalProperties: - $ref: '#/definitions/cacao.ExtensionDefinition' - type: object - external_references: - items: - $ref: '#/definitions/cacao.ExternalReferences' - type: array - id: - type: string - impact: - type: integer - labels: - items: - type: string - type: array - markings: - items: - type: string - type: array - modified: - type: string - name: - type: string - playbook_extensions: - $ref: '#/definitions/cacao.Extensions' - playbook_types: - items: - type: string - type: array - playbook_variables: - additionalProperties: - $ref: '#/definitions/cacao.Variable' - type: object - priority: - type: integer - severity: - type: integer - spec_version: - type: string - target_definitions: - additionalProperties: - $ref: '#/definitions/cacao.AgentTarget' - type: object - type: - type: string - valid_from: - type: string - valid_until: - type: string - workflow: - $ref: '#/definitions/cacao.Workflow' - workflow_exception: - type: string - workflow_start: - type: string - required: - - created - - created_by - - id - - modified - - name - - spec_version - - type - - workflow - - workflow_start - type: object - cacao.Step: - properties: - agent: - type: string - authentication_info: - type: string - cases: - additionalProperties: - type: string - type: object - commands: - items: - $ref: '#/definitions/cacao.Command' - type: array - condition: - type: string - delay: - type: integer - description: - type: string - external_references: - items: - $ref: '#/definitions/cacao.ExternalReferences' - type: array - id: - type: string - in_args: - items: - type: string - type: array - name: - type: string - next_steps: - items: - type: string - type: array - on_completion: - type: string - on_failure: - type: string - on_false: - type: string - on_success: - type: string - on_true: - type: string - out_args: - items: - type: string - type: array - owner: - type: string - playbook_id: - type: string - playbook_version: - type: string - step_extensions: - $ref: '#/definitions/cacao.Extensions' - step_variables: - additionalProperties: - $ref: '#/definitions/cacao.Variable' - type: object - switch: - type: string - targets: - items: - type: string - type: array - timeout: - type: integer - type: - type: string - required: - - type - type: object - cacao.Variable: - properties: - constant: - type: boolean - description: - type: string - external: - type: boolean - name: - type: string - type: - type: string - value: - type: string - required: - - type - type: object - cacao.Workflow: - additionalProperties: - $ref: '#/definitions/cacao.Step' - type: object -info: - contact: {} -paths: - /playbook/: - get: - description: return all stored playbooks default limit:100 - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/cacao.Playbook' - type: array - summary: gets all the UUIDs for the stored playbooks - tags: - - playbook - post: - consumes: - - application/json - description: submit a new playbook api - parameters: - - description: playbook - in: body - name: data - required: true - schema: - $ref: '#/definitions/cacao.Playbook' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/cacao.Playbook' - summary: submit playbook via the api - tags: - - playbook - /playbook/{id}: - delete: - consumes: - - application/json - description: delete playbook by Id - parameters: - - description: playbook ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - summary: delete playbook by Id - tags: - - playbook - get: - consumes: - - application/json - description: get playbook by ID - parameters: - - description: playbook ID - in: path - name: id - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/cacao.Playbook' - summary: get CACAO playbook by its ID - tags: - - playbook - put: - consumes: - - application/json - description: update playbook by Id - parameters: - - description: playbook Id - in: path - name: id - required: true - type: string - - description: playbook - in: body - name: data - required: true - schema: - $ref: '#/definitions/cacao.Playbook' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/cacao.Playbook' - summary: update playbook - tags: - - playbook - /playbook/meta: - get: - description: get playbook meta information for playbook - produces: - - application/json - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/api.PlaybookMeta' - type: array - summary: gets all the meta information for the stored playbooks - tags: - - playbook - /trigger/workflow: - post: - consumes: - - application/json - description: trigger workflow - parameters: - - description: execute playbook by payload - in: body - name: playbook - required: true - schema: - $ref: '#/definitions/cacao.Playbook' - produces: - - application/json - responses: - "200": - description: '{"execution_id":"uuid","payload":"playbook--uuid"}' - summary: trigger a workflow with via cacao payload - tags: - - trigger -swagger: "2.0" diff --git a/makefile b/makefile index d3d77c7f..33ee41d2 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: all test clean build docker run pre-docker-build +.PHONY: all test integration-test ci-test clean build docker run pre-docker-build BINARY_NAME=soarca DIRECTORY = $(sort $(dir $(wildcard ./test/*/))) @@ -10,24 +10,22 @@ GOLDFLAGS += -X main.Buildtime=$(BUILDTIME) GOFLAGS = -ldflags "$(GOLDFLAGS)" lint: - golangci-lint run -v + mkdir -p swaggerdocs + swag init -o swaggerdocs + golangci-lint run --timeout 5m -v build: - swag init + mkdir -p swaggerdocs + swag init -o swaggerdocs CGO_ENABLED=0 go build -o ./build/soarca $(GOFLAGS) main.go test: - go test test/cacao/*_test.go -v - go test test/logger/*_test.go -v - go test test/decomposer/*_test.go -v - go test test/executor/*_test.go -v - go test test/routes/playbook_api/*_test.go -v - go test test/routes/trigger_api/*_test.go -v - go test test/capability/fin/*_test.go -v - go test test/capability/ssh/*_test.go -v - go test test/capability/http/*_test.go -v - go test test/finmodel/*_test.go -v - go test test/finprotocol/*_test.go -v + go test ./test/unittest/... -v + +integration-test: + go test ./test/integration/... -v + +ci-test: test integration-test clean: rm -rf build/soarca* build/main @@ -36,7 +34,8 @@ clean: compile: echo "Compiling for every OS and Platform" - swag init + mkdir -p swaggerdocs + swag init -o swaggerdocs CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) main.go CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) main.go @@ -49,7 +48,8 @@ sbom: CGO_ENABLED=0 GOOS=windows GOARCH=amd64 cyclonedx-gomod app -json -licenses -output bin/${BINARY_NAME}-${VERSION}-windows-amd64.bom.json pre-docker-build: - swag init + mkdir -p swaggerdocs + swag init -o swaggerdocs GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) main.go docker: pre-docker-build diff --git a/routes/swagger/swagger_endpoints.go b/routes/swagger/swagger_endpoints.go index e7ffb180..73f681d0 100644 --- a/routes/swagger/swagger_endpoints.go +++ b/routes/swagger/swagger_endpoints.go @@ -1,7 +1,7 @@ package swagger import ( - "soarca/docs" + "soarca/swaggerdocs" "github.com/gin-gonic/gin" swaggerfiles "github.com/swaggo/files" @@ -9,7 +9,7 @@ import ( ) func Routes(route *gin.Engine) { - docs.SwaggerInfo.BasePath = "/" + swaggerdocs.SwaggerInfo.BasePath = "/" swagger := route.Group("/swagger") { swagger.GET("/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) diff --git a/test/capability/http/http_test.go b/test/integration/capability/http/http_integration_test.go similarity index 60% rename from test/capability/http/http_test.go rename to test/integration/capability/http/http_integration_test.go index 3087219d..404da926 100644 --- a/test/capability/http/http_test.go +++ b/test/integration/capability/http/http_integration_test.go @@ -1,14 +1,12 @@ -package ssh_test +package http_integrations_test import ( - "errors" "fmt" "soarca/internal/capability/http" "soarca/models/cacao" "soarca/models/execution" "testing" - "github.com/go-playground/assert/v2" "github.com/google/uuid" ) @@ -134,87 +132,3 @@ func TestHttpBasicAuth(t *testing.T) { } fmt.Println(results) } - -// Tests for data fetching from command -func TestHttpObtainMethodFromCommandValid(t *testing.T) { - - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "POST https://google.com/", - } - - httpMethod, httpUrl, err := http.ObtainHttpMethodAndUrlFromCommand(expectedCommand) - assert.Equal(t, httpMethod, "POST") - assert.Equal(t, httpUrl, "https://google.com/") - assert.Equal(t, err, nil) -} - -func TestHttpObtainMethodAndUrlFromCommandInvalid(t *testing.T) { - - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "https://google.com/", // No method - } - - httpMethod, httpUrl, err := http.ObtainHttpMethodAndUrlFromCommand(expectedCommand) - - assert.Equal(t, httpMethod, "") - assert.Equal(t, httpUrl, "") - assert.Equal(t, err, errors.New("method or url missing from command")) - -} - -// Tests obtain content from command -func TestObtainHttpRequestContentDataFromCommandBothTypes(t *testing.T) { - test_content := "414141" - test_b64_content := "923948a09a" - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "GET 0.0.0.0:80/", - Content: test_content, - ContentB64: test_b64_content, - } - - ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) - - assert.Equal(t, ret_content, []byte(test_content)) - assert.Equal(t, err, nil) -} -func TestObtainHttpRequestContentDataFromCommandB64Only(t *testing.T) { - test_b64_content := "R08gU09BUkNBIQ==" - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "GET 0.0.0.0:80/", - ContentB64: test_b64_content, - } - - ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) - - assert.Equal(t, ret_content, []byte("GO SOARCA!")) - assert.Equal(t, err, nil) -} -func TestObtainHttpRequestContentDataFromCommandPlainTextOnly(t *testing.T) { - test_content := "414141" - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "GET 0.0.0.0:80/", - Content: test_content, - } - - ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) - - assert.Equal(t, ret_content, []byte(test_content)) - assert.Equal(t, err, nil) -} - -func TestObtainHttpRequestContentDataFromCommandEmpty(t *testing.T) { - expectedCommand := cacao.Command{ - Type: "http-api", - Command: "GET 0.0.0.0:80/", - } - - ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) - - assert.Equal(t, ret_content, nil) - assert.Equal(t, err, nil) -} diff --git a/test/integration/capability/ssh/ssh_integration_test.go b/test/integration/capability/ssh/ssh_integration_test.go new file mode 100644 index 00000000..fae7d450 --- /dev/null +++ b/test/integration/capability/ssh/ssh_integration_test.go @@ -0,0 +1,56 @@ +package ssh_integration_test + +import ( + "fmt" + "soarca/internal/capability/ssh" + "soarca/models/cacao" + "soarca/models/execution" + "testing" + + "github.com/google/uuid" +) + +func TestSshConnection(t *testing.T) { + sshCapability := new(ssh.SshCapability) + + expectedCommand := cacao.Command{ + Type: "ssh", + Command: "ls -la", + } + + expectedAuthenticationInformation := cacao.AuthenticationInformation{ + ID: "some-authid-1", + Type: "user-auth", + Username: "sshtest", + Password: "pdKY77qNxpI5MAizirtjCVOcm0KFKIs"} + + expectedTarget := cacao.AgentTarget{ + Type: "ssh", + Address: map[string][]string{"ipv4": {"localhost"}}, + // Port: "22", + AuthInfoIdentifier: "some-authid-1", + } + + expectedVariables := cacao.Variable{ + Type: "string", + Name: "var1", + Value: "testing", + } + + var executionId, _ = uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8") + var playbookId = "playbook--d09351a2-a075-40c8-8054-0b7c423db83f" + var stepId = "step--81eff59f-d084-4324-9e0a-59e353dbd28f" + var metadata = execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId, StepId: stepId} + results, err := sshCapability.Execute(metadata, + expectedCommand, + expectedAuthenticationInformation, + expectedTarget, + cacao.VariableMap{expectedVariables.Name: expectedVariables}) + if err != nil { + fmt.Println(err) + t.Fail() + } + + fmt.Println(results) + +} diff --git a/test/mqtt/mqtt_test.go b/test/manual/mqtt/mqtt_test.go similarity index 100% rename from test/mqtt/mqtt_test.go rename to test/manual/mqtt/mqtt_test.go diff --git a/test/cacao/cacao_test.go b/test/unittest/cacao/cacao_test.go similarity index 100% rename from test/cacao/cacao_test.go rename to test/unittest/cacao/cacao_test.go diff --git a/test/cacao/playbooks/changed-playbook.json b/test/unittest/cacao/playbooks/changed-playbook.json similarity index 100% rename from test/cacao/playbooks/changed-playbook.json rename to test/unittest/cacao/playbooks/changed-playbook.json diff --git a/test/cacao/playbooks/infinite_playbook.json b/test/unittest/cacao/playbooks/infinite_playbook.json similarity index 100% rename from test/cacao/playbooks/infinite_playbook.json rename to test/unittest/cacao/playbooks/infinite_playbook.json diff --git a/test/cacao/playbooks/invalid_email_playbook.json b/test/unittest/cacao/playbooks/invalid_email_playbook.json similarity index 100% rename from test/cacao/playbooks/invalid_email_playbook.json rename to test/unittest/cacao/playbooks/invalid_email_playbook.json diff --git a/test/cacao/playbooks/invalid_playbook.json b/test/unittest/cacao/playbooks/invalid_playbook.json similarity index 100% rename from test/cacao/playbooks/invalid_playbook.json rename to test/unittest/cacao/playbooks/invalid_playbook.json diff --git a/test/cacao/playbooks/missing_step_playbook.json b/test/unittest/cacao/playbooks/missing_step_playbook.json similarity index 100% rename from test/cacao/playbooks/missing_step_playbook.json rename to test/unittest/cacao/playbooks/missing_step_playbook.json diff --git a/test/cacao/playbooks/parallels_playbook.json b/test/unittest/cacao/playbooks/parallels_playbook.json similarity index 100% rename from test/cacao/playbooks/parallels_playbook.json rename to test/unittest/cacao/playbooks/parallels_playbook.json diff --git a/test/cacao/playbooks/playbook.json b/test/unittest/cacao/playbooks/playbook.json similarity index 100% rename from test/cacao/playbooks/playbook.json rename to test/unittest/cacao/playbooks/playbook.json diff --git a/test/cacao/validators_test.go b/test/unittest/cacao/validators_test.go similarity index 100% rename from test/cacao/validators_test.go rename to test/unittest/cacao/validators_test.go diff --git a/test/cacao/variables_test.go b/test/unittest/cacao/variables_test.go similarity index 100% rename from test/cacao/variables_test.go rename to test/unittest/cacao/variables_test.go diff --git a/test/capability/fin/fin_test.go b/test/unittest/capability/fin/fin_test.go similarity index 97% rename from test/capability/fin/fin_test.go rename to test/unittest/capability/fin/fin_test.go index 4c1af056..9863cbcd 100644 --- a/test/capability/fin/fin_test.go +++ b/test/unittest/capability/fin/fin_test.go @@ -5,7 +5,7 @@ import ( "soarca/models/cacao" "soarca/models/execution" model "soarca/models/fin" - "soarca/test/mocks/mock_finprotocol" + "soarca/test/unittest/mocks/mock_finprotocol" "testing" "github.com/go-playground/assert/v2" diff --git a/test/unittest/capability/http/http_test.go b/test/unittest/capability/http/http_test.go new file mode 100644 index 00000000..be775175 --- /dev/null +++ b/test/unittest/capability/http/http_test.go @@ -0,0 +1,94 @@ +package ssh_test + +import ( + "errors" + "soarca/internal/capability/http" + "soarca/models/cacao" + "testing" + + "github.com/go-playground/assert/v2" +) + +// Tests for data fetching from command +func TestHttpObtainMethodFromCommandValid(t *testing.T) { + + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "POST https://google.com/", + } + + httpMethod, httpUrl, err := http.ObtainHttpMethodAndUrlFromCommand(expectedCommand) + assert.Equal(t, httpMethod, "POST") + assert.Equal(t, httpUrl, "https://google.com/") + assert.Equal(t, err, nil) +} + +func TestHttpObtainMethodAndUrlFromCommandInvalid(t *testing.T) { + + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "https://google.com/", // No method + } + + httpMethod, httpUrl, err := http.ObtainHttpMethodAndUrlFromCommand(expectedCommand) + + assert.Equal(t, httpMethod, "") + assert.Equal(t, httpUrl, "") + assert.Equal(t, err, errors.New("method or url missing from command")) + +} + +// Tests obtain content from command +func TestObtainHttpRequestContentDataFromCommandBothTypes(t *testing.T) { + test_content := "414141" + test_b64_content := "923948a09a" + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "GET 0.0.0.0:80/", + Content: test_content, + ContentB64: test_b64_content, + } + + ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) + + assert.Equal(t, ret_content, []byte(test_content)) + assert.Equal(t, err, nil) +} +func TestObtainHttpRequestContentDataFromCommandB64Only(t *testing.T) { + test_b64_content := "R08gU09BUkNBIQ==" + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "GET 0.0.0.0:80/", + ContentB64: test_b64_content, + } + + ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) + + assert.Equal(t, ret_content, []byte("GO SOARCA!")) + assert.Equal(t, err, nil) +} +func TestObtainHttpRequestContentDataFromCommandPlainTextOnly(t *testing.T) { + test_content := "414141" + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "GET 0.0.0.0:80/", + Content: test_content, + } + + ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) + + assert.Equal(t, ret_content, []byte(test_content)) + assert.Equal(t, err, nil) +} + +func TestObtainHttpRequestContentDataFromCommandEmpty(t *testing.T) { + expectedCommand := cacao.Command{ + Type: "http-api", + Command: "GET 0.0.0.0:80/", + } + + ret_content, err := http.ObtainHttpRequestContentDataFromCommand(expectedCommand) + + assert.Equal(t, ret_content, nil) + assert.Equal(t, err, nil) +} diff --git a/test/capability/ssh/ssh_test.go b/test/unittest/capability/ssh/ssh_test.go similarity index 74% rename from test/capability/ssh/ssh_test.go rename to test/unittest/capability/ssh/ssh_test.go index 06ae9445..11a16f8f 100644 --- a/test/capability/ssh/ssh_test.go +++ b/test/unittest/capability/ssh/ssh_test.go @@ -2,61 +2,13 @@ package ssh_test import ( "errors" - "fmt" "soarca/internal/capability/ssh" "soarca/models/cacao" - "soarca/models/execution" "testing" "github.com/go-playground/assert/v2" - "github.com/google/uuid" ) -func TestSshConnection(t *testing.T) { - sshCapability := new(ssh.SshCapability) - - expectedCommand := cacao.Command{ - Type: "ssh", - Command: "ls -la", - } - - expectedAuthenticationInformation := cacao.AuthenticationInformation{ - ID: "some-authid-1", - Type: "user-auth", - Username: "sshtest", - Password: "pdKY77qNxpI5MAizirtjCVOcm0KFKIs"} - - expectedTarget := cacao.AgentTarget{ - Type: "ssh", - Address: map[string][]string{"ipv4": {"localhost"}}, - // Port: "22", - AuthInfoIdentifier: "some-authid-1", - } - - expectedVariables := cacao.Variable{ - Type: "string", - Name: "var1", - Value: "testing", - } - - var executionId, _ = uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8") - var playbookId = "playbook--d09351a2-a075-40c8-8054-0b7c423db83f" - var stepId = "step--81eff59f-d084-4324-9e0a-59e353dbd28f" - var metadata = execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId, StepId: stepId} - results, err := sshCapability.Execute(metadata, - expectedCommand, - expectedAuthenticationInformation, - expectedTarget, - cacao.VariableMap{expectedVariables.Name: expectedVariables}) - if err != nil { - fmt.Println(err) - t.Fail() - } - - fmt.Println(results) - -} - func TestStripSshPrependWithPrepend(t *testing.T) { command := "ssh ls -la" result := ssh.StripSshPrepend(command) diff --git a/test/database/projections_test.go b/test/unittest/database/projections_test.go similarity index 100% rename from test/database/projections_test.go rename to test/unittest/database/projections_test.go diff --git a/test/decomposer/decomposer_test.go b/test/unittest/decomposer/decomposer_test.go similarity index 99% rename from test/decomposer/decomposer_test.go rename to test/unittest/decomposer/decomposer_test.go index 0425adda..ae6b2da3 100644 --- a/test/decomposer/decomposer_test.go +++ b/test/unittest/decomposer/decomposer_test.go @@ -8,8 +8,8 @@ import ( "soarca/internal/decomposer" "soarca/models/cacao" "soarca/models/execution" - "soarca/test/mocks/mock_executor" - "soarca/test/mocks/mock_guid" + "soarca/test/unittest/mocks/mock_executor" + "soarca/test/unittest/mocks/mock_guid" "github.com/go-playground/assert/v2" "github.com/google/uuid" diff --git a/test/executor/executor_test.go b/test/unittest/executor/executor_test.go similarity index 98% rename from test/executor/executor_test.go rename to test/unittest/executor/executor_test.go index 9a51659a..1cf33fde 100644 --- a/test/executor/executor_test.go +++ b/test/unittest/executor/executor_test.go @@ -6,7 +6,7 @@ import ( "soarca/internal/executer" "soarca/models/cacao" "soarca/models/execution" - "soarca/test/mocks/mock_capability" + "soarca/test/unittest/mocks/mock_capability" "testing" "github.com/go-playground/assert/v2" diff --git a/test/finmodel/finmodel_test.go b/test/unittest/finmodel/finmodel_test.go similarity index 100% rename from test/finmodel/finmodel_test.go rename to test/unittest/finmodel/finmodel_test.go diff --git a/test/finprotocol/finprotocol_test.go b/test/unittest/finprotocol/finprotocol_test.go similarity index 98% rename from test/finprotocol/finprotocol_test.go rename to test/unittest/finprotocol/finprotocol_test.go index 0467ff77..c0c55481 100644 --- a/test/finprotocol/finprotocol_test.go +++ b/test/unittest/finprotocol/finprotocol_test.go @@ -9,7 +9,7 @@ import ( "soarca/models/cacao" "soarca/models/fin" model "soarca/models/fin" - "soarca/test/mocks/mock_mqtt" + "soarca/test/unittest/mocks/mock_mqtt" "testing" "time" diff --git a/test/logger/log_test.go b/test/unittest/logger/log_test.go similarity index 100% rename from test/logger/log_test.go rename to test/unittest/logger/log_test.go diff --git a/test/mocks/mock_capability/mock_capability.go b/test/unittest/mocks/mock_capability/mock_capability.go similarity index 100% rename from test/mocks/mock_capability/mock_capability.go rename to test/unittest/mocks/mock_capability/mock_capability.go diff --git a/test/mocks/mock_decomposer/mock_decomposer.go b/test/unittest/mocks/mock_decomposer/mock_decomposer.go similarity index 100% rename from test/mocks/mock_decomposer/mock_decomposer.go rename to test/unittest/mocks/mock_decomposer/mock_decomposer.go diff --git a/test/mocks/mock_executor/mock_executor.go b/test/unittest/mocks/mock_executor/mock_executor.go similarity index 100% rename from test/mocks/mock_executor/mock_executor.go rename to test/unittest/mocks/mock_executor/mock_executor.go diff --git a/test/mocks/mock_finprotocol/mock_finprotocol.go b/test/unittest/mocks/mock_finprotocol/mock_finprotocol.go similarity index 100% rename from test/mocks/mock_finprotocol/mock_finprotocol.go rename to test/unittest/mocks/mock_finprotocol/mock_finprotocol.go diff --git a/test/mocks/mock_guid/mock_guid.go b/test/unittest/mocks/mock_guid/mock_guid.go similarity index 100% rename from test/mocks/mock_guid/mock_guid.go rename to test/unittest/mocks/mock_guid/mock_guid.go diff --git a/test/mocks/mock_mqtt/mock_mqttclient.go b/test/unittest/mocks/mock_mqtt/mock_mqttclient.go similarity index 100% rename from test/mocks/mock_mqtt/mock_mqttclient.go rename to test/unittest/mocks/mock_mqtt/mock_mqttclient.go diff --git a/test/mocks/mock_mqtt/mock_mqttmessage.go b/test/unittest/mocks/mock_mqtt/mock_mqttmessage.go similarity index 100% rename from test/mocks/mock_mqtt/mock_mqttmessage.go rename to test/unittest/mocks/mock_mqtt/mock_mqttmessage.go diff --git a/test/mocks/mock_mqtt/mock_mqtttoken.go b/test/unittest/mocks/mock_mqtt/mock_mqtttoken.go similarity index 100% rename from test/mocks/mock_mqtt/mock_mqtttoken.go rename to test/unittest/mocks/mock_mqtt/mock_mqtttoken.go diff --git a/test/mocks/mock_utils/http/mock_http.go b/test/unittest/mocks/mock_utils/http/mock_http.go similarity index 100% rename from test/mocks/mock_utils/http/mock_http.go rename to test/unittest/mocks/mock_utils/http/mock_http.go diff --git a/test/mocks/playbook/mock_playbook.go b/test/unittest/mocks/playbook/mock_playbook.go similarity index 100% rename from test/mocks/playbook/mock_playbook.go rename to test/unittest/mocks/playbook/mock_playbook.go diff --git a/test/routes/playbook.json b/test/unittest/routes/playbook.json similarity index 100% rename from test/routes/playbook.json rename to test/unittest/routes/playbook.json diff --git a/test/routes/playbook_api/playbook_api_test.go b/test/unittest/routes/playbook_api/playbook_api_test.go similarity index 99% rename from test/routes/playbook_api/playbook_api_test.go rename to test/unittest/routes/playbook_api/playbook_api_test.go index 525a7f7d..05bc3779 100644 --- a/test/routes/playbook_api/playbook_api_test.go +++ b/test/unittest/routes/playbook_api/playbook_api_test.go @@ -14,7 +14,7 @@ import ( "soarca/models/cacao" "soarca/models/decoder" playbookRouter "soarca/routes/playbook" - mock_playbook "soarca/test/mocks/playbook" + mock_playbook "soarca/test/unittest/mocks/playbook" "github.com/gin-gonic/gin" "github.com/stretchr/testify/assert" diff --git a/test/routes/trigger_api/tigger_api_test.go b/test/unittest/routes/trigger_api/tigger_api_test.go similarity index 95% rename from test/routes/trigger_api/tigger_api_test.go rename to test/unittest/routes/trigger_api/tigger_api_test.go index 2fdac1f2..cbc48270 100644 --- a/test/routes/trigger_api/tigger_api_test.go +++ b/test/unittest/routes/trigger_api/tigger_api_test.go @@ -12,7 +12,7 @@ import ( "soarca/internal/decomposer" "soarca/models/cacao" "soarca/routes/trigger" - "soarca/test/mocks/mock_decomposer" + "soarca/test/unittest/mocks/mock_decomposer" "github.com/gin-gonic/gin" "github.com/go-playground/assert/v2" diff --git a/test/utils/http/http_test.go b/test/unittest/utils/http/http_test.go similarity index 100% rename from test/utils/http/http_test.go rename to test/unittest/utils/http/http_test.go