Skip to content

Commit

Permalink
Modifed component test
Browse files Browse the repository at this point in the history
  • Loading branch information
afek854 committed Nov 7, 2024
1 parent 55b8235 commit 233854d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
23 changes: 10 additions & 13 deletions tests/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,44 +624,41 @@ func Test_11_EndpointTest(t *testing.T) {
assert.NoError(t, endpointTraffic.WaitForApplicationProfile(80, "ready"))

// Merge methods
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:8000"}, "")
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:80"}, "")
assert.NoError(t, err)
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:8000", "--post-data", "test-data"}, "")
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:80", "--post-data", "test-data"}, "")

// Merge dynamic
for i := 0; i < threshold; i++ {
endpointTraffic.ExecIntoPod([]string{"wget", fmt.Sprintf("http://127.0.0.1:8000/users/%d", i)}, "")
endpointTraffic.ExecIntoPod([]string{"wget", fmt.Sprintf("http://127.0.0.1:80/users/%d", i)}, "")
}

// Merge headers
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:8000/users/99", "--header", "Connection:1234r"}, "")
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:8000/users/12", "--header", "Connection:ziz"}, "")
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:80/users/99", "--header", "Connection:1234r"}, "")
_, _, err = endpointTraffic.ExecIntoPod([]string{"wget", "http://127.0.0.1:80/users/12", "--header", "Connection:ziz"}, "")

err = endpointTraffic.WaitForApplicationProfileCompletion(80)
if err != nil {
t.Errorf("Error waiting for application profile to be completed: %v", err)
}
err = endpointTraffic.WaitForApplicationProfileCompletion(10)

applicationProfile, err := endpointTraffic.GetApplicationProfile()

headers := map[string][]string{"Connection": {"close"}, "Host": {"127.0.0.1:8000"}}
headers := map[string][]string{"Connection": {"close"}, "Host": {"127.0.0.1:80"}}
rawJSON, err := json.Marshal(headers)
assert.NoError(t, err)

endpoint2 := v1beta1.HTTPEndpoint{
Endpoint: ":8000/",
Endpoint: ":80/",
Methods: []string{"GET", "POST"},
Internal: false,
Direction: "inbound",
Headers: rawJSON,
}

headers = map[string][]string{"Host": {"127.0.0.1:8000"}, "Connection": {"1234r", "close", "ziz"}}
headers = map[string][]string{"Host": {"127.0.0.1:80"}, "Connection": {"1234r", "close", "ziz"}}
rawJSON, err = json.Marshal(headers)
assert.NoError(t, err)

endpoint1 := v1beta1.HTTPEndpoint{
Endpoint: ":8000/users/" + dynamicpathdetector.DynamicIdentifier,
Endpoint: ":80/users/" + dynamicpathdetector.DynamicIdentifier,
Methods: []string{"GET"},
Internal: false,
Direction: "inbound",
Expand Down
35 changes: 34 additions & 1 deletion tests/resources/endpoint-traffic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,39 @@ spec:
- name: endpoint-traffic
image: armoafekb/afek-b-tests:ptrace_test
imagePullPolicy: Always
command: [ "/bin/sh", "-c", "mkdir -p users && for i in $(seq 0 104); do touch users/$i; done && python3 -m http.server" ]
# Create a volume mount for the script
volumeMounts:
- name: server-script
mountPath: /app
command: ["/bin/sh"]
args: ["-c", "echo '$(SERVER_SCRIPT)' > /app/server.py && python3 /app/server.py"]
ports:
- containerPort: 80
env:
- name: SERVER_SCRIPT
value: |
from http.server import HTTPServer, BaseHTTPRequestHandler
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(b"GET request received successfully")
def do_POST(self):
content_length = int(self.headers["Content-Length"])
post_data = self.rfile.read(content_length)
print(f"Received POST data: {post_data.decode()}")
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(b"POST request received successfully")
def run_server(port=80):
server_address = ("", port)
httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
print(f"Server running on port {port}")
httpd.serve_forever()
if __name__ == "__main__":
run_server()
volumes:
- name: server-script
emptyDir: {}

0 comments on commit 233854d

Please sign in to comment.