Verify requests against model (fixes #15)

This commit is contained in:
Jakob Borg
2014-01-06 21:31:36 +01:00
parent 28d3936a3c
commit 4b11e66914
3 changed files with 39 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package model
import (
"bytes"
"os"
"reflect"
"testing"
@@ -317,3 +318,25 @@ func TestForgetNode(t *testing.T) {
t.Errorf("Model len(need) incorrect (%d != %d)", l1, l2)
}
}
func TestRequest(t *testing.T) {
m := NewModel("testdata")
fs, _ := m.Walk(false)
m.ReplaceLocal(fs)
bs, err := m.Request("some node", "foo", 0, 6, nil)
if err != nil {
t.Fatal(err)
}
if bytes.Compare(bs, []byte("foobar")) != 0 {
t.Errorf("Incorrect data from request: %q", string(bs))
}
bs, err = m.Request("some node", "../walk.go", 0, 6, nil)
if err == nil {
t.Error("Unexpected nil error on insecure file read")
}
if bs != nil {
t.Errorf("Unexpected non nil data on insecure file read: %q", string(bs))
}
}