Download this file
| 1 | package oficinaid |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/rastrillo/rastrillo/auth" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "testing" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func TestIDDuplicateSessionCannotBypassResolution(t *testing.T) { |
| 12 | s, k := fixture(t) |
| 13 | _, token := establish(t, s, k, time.Now().Truncate(time.Second)) |
| 14 | authentication, e := auth.New(auth.Config{DB: s.DB, Origin: s.Origin, InstanceKey: "test-identity-cookie-key", ProofOff: true}) |
| 15 | if e != nil { |
| 16 | t.Fatal(e) |
| 17 | } |
| 18 | h := &HTTP{Store: s, Auth: authentication, Render: func(w http.ResponseWriter, _ *http.Request, _ View, status int) { w.WriteHeader(status) }} |
| 19 | r := httptest.NewRequest("GET", s.Origin+"/work", nil) |
| 20 | r.AddCookie(&http.Cookie{Name: authentication.SessionCookie(), Value: token}) |
| 21 | r.AddCookie(&http.Cookie{Name: authentication.SessionCookie(), Value: token}) |
| 22 | out := httptest.NewRecorder() |
| 23 | h.Authenticate(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(204) })).ServeHTTP(out, r) |
| 24 | if out.Code < 400 { |
| 25 | t.Fatal("Home subject escaped identity resolution", out.Code) |
| 26 | } |
| 27 | } |
| 28 | |