Skip to content

Commit

Permalink
moved insecure tests to integration
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbITCybErSeC committed May 8, 2024
1 parent 3ec3a7b commit dd43add
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 68 deletions.
84 changes: 72 additions & 12 deletions test/integration/capability/http/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package http_integrations_test

import (
"fmt"
"testing"

"soarca/internal/capability/http"
"soarca/models/cacao"
"soarca/models/execution"
httpUtil "soarca/utils/http"
"testing"

http "soarca/utils/http"

"github.com/go-playground/assert"

Check failure on line 14 in test/integration/capability/http/http_integration_test.go

View workflow job for this annotation

GitHub Actions / Run ci-tests

no required module provides package github.com/go-playground/assert; to add it:
"github.com/google/uuid"
)

Expand All @@ -26,15 +30,15 @@ func TestHttpConnection(t *testing.T) {
Headers: map[string][]string{"accept": {"application/json"}},
}

var variable1 = cacao.Variable{
variable1 := cacao.Variable{
Type: "string",
Name: "test_auth",
Value: "",
}

var executionId, _ = uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
var playbookId, _ = uuid.Parse("playbook--d09351a2-a075-40c8-8054-0b7c423db83f")
var stepId, _ = uuid.Parse("action--81eff59f-d084-4324-9e0a-59e353dbd28f")
executionId, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
playbookId, _ := uuid.Parse("playbook--d09351a2-a075-40c8-8054-0b7c423db83f")
stepId, _ := uuid.Parse("action--81eff59f-d084-4324-9e0a-59e353dbd28f")

metadata := execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId.String(), StepId: stepId.String()}
// But what to do if there is no target and no AuthInfo?
Expand Down Expand Up @@ -74,9 +78,9 @@ func TestHttpOAuth2(t *testing.T) {
Headers: map[string][]string{"accept": {"application/json"}},
}

var executionId, _ = uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
var playbookId, _ = uuid.Parse("d09351a2-a075-40c8-8054-0b7c423db83f")
var stepId, _ = uuid.Parse("81eff59f-d084-4324-9e0a-59e353dbd28f")
executionId, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
playbookId, _ := uuid.Parse("d09351a2-a075-40c8-8054-0b7c423db83f")
stepId, _ := uuid.Parse("81eff59f-d084-4324-9e0a-59e353dbd28f")
metadata := execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId.String(), StepId: stepId.String()}
results, err := httpCapability.Execute(
metadata,
Expand All @@ -100,7 +104,7 @@ func TestHttpBasicAuth(t *testing.T) {

target := cacao.AgentTarget{
Address: map[cacao.NetAddressType][]string{
"url": []string{url},
"url": {url},
},
AuthInfoIdentifier: "d0c7e6a0-f7fe-464e-9935-e6b3443f5b91",
}
Expand All @@ -117,9 +121,9 @@ func TestHttpBasicAuth(t *testing.T) {
Command: "GET / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
}
var executionId, _ = uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
var playbookId, _ = uuid.Parse("d09351a2-a075-40c8-8054-0b7c423db83f")
var stepId, _ = uuid.Parse("81eff59f-d084-4324-9e0a-59e353dbd28f")
executionId, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
playbookId, _ := uuid.Parse("d09351a2-a075-40c8-8054-0b7c423db83f")
stepId, _ := uuid.Parse("81eff59f-d084-4324-9e0a-59e353dbd28f")
metadata := execution.Metadata{ExecutionId: executionId, PlaybookId: playbookId.String(), StepId: stepId.String()}
results, err := httpCapability.Execute(
metadata,
Expand All @@ -133,3 +137,59 @@ func TestHttpBasicAuth(t *testing.T) {
}
fmt.Println(results)
}

func TestInsecureHTTPConnection(t *testing.T) {
httpRequest := http.HttpRequest{}

target := cacao.AgentTarget{
Address: map[cacao.NetAddressType][]string{
"url": {"https://localhost/get"},
},
}
command := cacao.Command{
Type: "http-api",
Command: "GET / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
}
httpOptions := http.HttpOptions{
Command: &command,
Target: &target,
}
httpRequest.SkipCertificateValidation(true)
response, err := httpRequest.Request(httpOptions)
t.Log(string(response))
if err != nil {
t.Error("http get request test has failed: ", err)
}
if len(response) == 0 {
t.Error("empty response")
}
t.Log(string(response))
assert.Equal(t, err, nil)
}

func TestInsecureHTTPConnectionWithFailure(t *testing.T) {
httpRequest := http.HttpRequest{}

target := cacao.AgentTarget{
Address: map[cacao.NetAddressType][]string{
"url": {"https://localhost/get"},
},
}
command := cacao.Command{
Type: "http-api",
Command: "GET / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
}
httpOptions := http.HttpOptions{
Command: &command,
Target: &target,
}

response, err := httpRequest.Request(httpOptions)
t.Log(string(response))
if err == nil {
t.Error("test should have failed as insecure is not allowed")
}
assert.NotEqual(t, err, nil)
}
56 changes: 0 additions & 56 deletions test/unittest/utils/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,62 +35,6 @@ type httpBinResponseBody struct {

// Test general http options, we do not check responses body, as these are variable for the general connection tests

func TestInsecureHTTPConnection(t *testing.T) {
httpRequest := http.HttpRequest{}

target := cacao.AgentTarget{
Address: map[cacao.NetAddressType][]string{
"url": {"https://localhost/get"},
},
}
command := cacao.Command{
Type: "http-api",
Command: "GET / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
}
httpOptions := http.HttpOptions{
Command: &command,
Target: &target,
}
httpRequest.SkipCertificateValidation(true)
response, err := httpRequest.Request(httpOptions)
t.Log(string(response))
if err != nil {
t.Error("http get request test has failed: ", err)
}
if len(response) == 0 {
t.Error("empty response")
}
t.Log(string(response))
assert.Equal(t, err, nil)
}

func TestInsecureHTTPConnectionWithFailure(t *testing.T) {
httpRequest := http.HttpRequest{}

target := cacao.AgentTarget{
Address: map[cacao.NetAddressType][]string{
"url": {"https://localhost/get"},
},
}
command := cacao.Command{
Type: "http-api",
Command: "GET / HTTP/1.1",
Headers: map[string][]string{"accept": {"application/json"}},
}
httpOptions := http.HttpOptions{
Command: &command,
Target: &target,
}

response, err := httpRequest.Request(httpOptions)
t.Log(string(response))
if err == nil {
t.Error("test should have failed as insecure is not allowed")
}
assert.NotEqual(t, err, nil)
}

func TestHttpGetConnection(t *testing.T) {
httpRequest := http.HttpRequest{}

Expand Down

0 comments on commit dd43add

Please sign in to comment.