Skip to content

Commit

Permalink
Merge pull request #3 from asteurer/main
Browse files Browse the repository at this point in the history
fixing bug
  • Loading branch information
asteurer authored Aug 18, 2024
2 parents c07ec32 + ec6f02c commit 22c8303
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ func ping(w http.ResponseWriter, r *http.Request) {

// validate checks the flag file's content with the request body to see if they match
func validate(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer r.Body.Close()
bodyBytes, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer r.Body.Close()

fileBytes, err := os.ReadFile(secretFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fileBytes, err := os.ReadFile(secretFilePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

if string(fileBytes) == string(bodyBytes) {
w.Write([]byte("Success! You found the flag."))
} else {
w.Write([]byte("The string submitted doesn't match the content of the flag file."))
}
if string(fileBytes) == string(bodyBytes) {
w.Write([]byte("Success! You found the flag."))
} else {
w.Write([]byte("The string submitted doesn't match the content of the flag file."))
}
}

Expand Down

0 comments on commit 22c8303

Please sign in to comment.