From f3859ea3e440d8607ca758a5a447cb774c2f125d Mon Sep 17 00:00:00 2001 From: Cesca <3009298@stud.hs-mannheim.de> Date: Wed, 26 Nov 2025 09:48:35 +0000 Subject: [PATCH] =?UTF-8?q?Curl=20Tests=20und=20kleine=20=C3=84nderung=20a?= =?UTF-8?q?n=20Cookies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/08/labor/08_loesungen/Cookies/main.go | 3 +- web/08/labor/08_loesungen/curlTests.txt | 92 +++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 web/08/labor/08_loesungen/curlTests.txt diff --git a/web/08/labor/08_loesungen/Cookies/main.go b/web/08/labor/08_loesungen/Cookies/main.go index 7c688a9..69a6b53 100644 --- a/web/08/labor/08_loesungen/Cookies/main.go +++ b/web/08/labor/08_loesungen/Cookies/main.go @@ -7,7 +7,7 @@ import ( "github.com/google/uuid" ) -// create Cookie +// create Cookie HTTP Handler func createHandler(w http.ResponseWriter, r *http.Request) { //UUID erzeugen @@ -49,6 +49,7 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) { } // Maxage - 1 löscht Cookie cookie.MaxAge = -1 + // schickt neuen Set Cookie Header an Browser http.SetCookie(w, cookie) fmt.Fprintln(w, "Cookie gelöscht") } diff --git a/web/08/labor/08_loesungen/curlTests.txt b/web/08/labor/08_loesungen/curlTests.txt new file mode 100644 index 0000000..56a14d6 --- /dev/null +++ b/web/08/labor/08_loesungen/curlTests.txt @@ -0,0 +1,92 @@ +######################################## +# AUFGABE 1 – Routing (/login, /logout) +# Server vorher starten im Routing-Ordner: +# cd /workspaces/lab-development-imb/web/08/labor/08_loesungen/Routing +# go run main.go +######################################## + +# Login testen +curl 'http://localhost:8080/login' + +# Logout testen +curl 'http://localhost:8080/logout' + + + +######################################## +# AUFGABE 2 – JSON-Daten empfangen +# Server vorher starten im JSON-Ordner: +# cd "/workspaces/lab-development-imb/web/08/labor/08_loesungen/JSONEmpfangen" +# go run main.go +######################################## + +# 2.1 Formular-Endpunkt /registrierung + +# Erfolgreicher POST mit Formulardaten (Status 200) +curl -X POST 'http://localhost:8080/registrierung' \ + -d 'vorname=Max' \ + -d 'nachname=Mustermann' \ + -d 'email=max@example.com' \ + -d 'handy=01701234567' \ + -d 'kurs=Webentwicklung Basics' \ + -d 'format=online' \ + -d 'session=abend' \ + -d 'agb=on' + +# Fehlerfall provozieren (z.B. Vorname fehlt → Status 400) +curl -X POST 'http://localhost:8080/registrierung' \ + -d 'nachname=Mustermann' \ + -d 'email=max@example.com' \ + -d 'format=online' \ + -d 'session=abend' \ + -d 'agb=on' + + +# 2.2 JSON-Endpunkt /registrierung-json + +# Erfolgreicher JSON-POST (Status 200, JSON wird zurückgegeben) +curl -X POST 'http://localhost:8080/registrierung-json' \ + -H 'Content-Type: application/json' \ + -d '{ + "vorname": "Max", + "nachname": "Mustermann", + "email": "max@example.com", + "handy": "01701234567", + "kurs": "Webentwicklung Basics", + "session": "abend", + "agb": "on", + "newsletter": "ja", + "equipment": "ja", + "format": "online" + }' + +# Fehlerfall: ungültiges JSON (Status 400, "Json ungültig") +curl -X POST 'http://localhost:8080/registrierung-json' \ + -H 'Content-Type: application/json' \ + -d 'ich bin kein gültiges json' + + + +######################################## +# AUFGABE 3 – Cookies mit UUID +# Server vorher starten im Cookies-Ordner: +# cd /workspaces/lab-development-imb/web/08/labor/08_loesungen/Cookies +# go run main.go +######################################## + +# 3.1 Cookie erzeugen (/create-cookie) +# Setzt Cookie "keks=" und zeigt die UUID an. +# Gleichzeitig speichern wir das Cookie in cookies.txt +curl -i --cookie-jar cookies.txt 'http://localhost:8080/create-cookie' + +# 3.2 Cookie anzeigen (/show-cookie) +# Liest Cookie "keks" aus cookies.txt und zeigt den Wert an. +curl -i --cookie cookies.txt 'http://localhost:8080/show-cookie' + +# 3.3 Cookie löschen (/delete-cookie) +# Setzt MaxAge = -1 und löscht den Cookie. +curl -i --cookie cookies.txt 'http://localhost:8080/delete-cookie' + +# 3.4 Optional: prüfen, dass er wirklich weg ist +curl -i --cookie cookies.txt 'http://localhost:8080/show-cookie' +# Erwartet: "Kein Cookie vorhanden"