Confirm that bird access was restricted (#49)

Co-authored-by: Kioubit <kioubit@localhost.invalid>
This commit is contained in:
Kioubit 2022-01-18 04:03:09 -05:00 committed by GitHub
parent 26efeb4996
commit 950c018b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
package main
import (
"bytes"
"io"
"net"
"net/http"
"strings"
)
// Read a line from bird socket, removing preceding status number, output it.
@ -67,7 +69,13 @@ func birdHandler(httpW http.ResponseWriter, httpR *http.Request) {
birdReadln(bird, nil)
birdWriteln(bird, "restrict")
birdReadln(bird, nil)
var restrictedConfirmation bytes.Buffer
birdReadln(bird, &restrictedConfirmation)
if !strings.Contains(restrictedConfirmation.String(), "Access restricted") {
httpW.WriteHeader(http.StatusInternalServerError)
httpW.Write([]byte("could not verify that bird access was restricted"))
return
}
birdWriteln(bird, query)
for birdReadln(bird, httpW) {
}