Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 5 | package caveats |
| 6 | |
| 7 | import ( |
| 8 | "net/http" |
| 9 | "time" |
Suharsh Sivakumar | ccbc764 | 2015-03-27 16:10:10 -0700 | [diff] [blame] | 10 | |
| 11 | "v.io/v23/security" |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | type mockCaveatSelector struct { |
| 15 | state string |
| 16 | } |
| 17 | |
| 18 | // NewMockCaveatSelector returns a CaveatSelector that always returns a default set |
| 19 | // of caveats: [exprity caveat with a 1h expiry, revocation caveat, and a method caveat |
| 20 | // for methods "methodA" and "methodB"] and the additional extension: "test-extension" |
| 21 | // This selector is only meant to be used during testing. |
| 22 | func NewMockCaveatSelector() CaveatSelector { |
| 23 | return &mockCaveatSelector{} |
| 24 | } |
| 25 | |
| 26 | func (s *mockCaveatSelector) Render(_, state, redirectURL string, w http.ResponseWriter, r *http.Request) error { |
| 27 | s.state = state |
| 28 | http.Redirect(w, r, redirectURL, http.StatusFound) |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | func (s *mockCaveatSelector) ParseSelections(r *http.Request) (caveats []CaveatInfo, state string, additionalExtension string, err error) { |
| 33 | caveats = []CaveatInfo{ |
| 34 | CaveatInfo{"Revocation", []interface{}{}}, |
| 35 | CaveatInfo{"Expiry", []interface{}{time.Now().Add(time.Hour)}}, |
| 36 | CaveatInfo{"Method", []interface{}{"methodA", "methodB"}}, |
Suharsh Sivakumar | ccbc764 | 2015-03-27 16:10:10 -0700 | [diff] [blame] | 37 | CaveatInfo{"PeerBlessings", []interface{}{security.BlessingPattern("peerA"), security.BlessingPattern("peerB")}}, |
Suharsh Sivakumar | a76dba6 | 2014-12-22 16:00:34 -0800 | [diff] [blame] | 38 | } |
| 39 | state = s.state |
| 40 | additionalExtension = "test-extension" |
| 41 | return |
| 42 | } |