Curl Tests und kleine Änderung an Cookies

branch-francesca
Francesca Bläse 2025-11-26 09:48:35 +00:00
parent 773145a856
commit f3859ea3e4
2 changed files with 94 additions and 1 deletions

View File

@ -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")
}

View File

@ -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=<UUID>" 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"