-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#373 set
vouch.document_root
for "vouch in a path"
- Loading branch information
Showing
14 changed files
with
245 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
vouch: | ||
document_root: /vouch_in_a_path | ||
domains: | ||
- example.com | ||
|
||
cookie: | ||
secure: false | ||
domain: example.com | ||
|
||
jwt: | ||
secret: testingsecret | ||
|
||
oauth: | ||
provider: google | ||
client_id: http://vouch.github.io | ||
auth_url: https://indielogin.com/auth | ||
callback_url: http://vouch.github.io:9090/auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
Copyright 2020 The Vouch Proxy Authors. | ||
Use of this source code is governed by The MIT License (MIT) that | ||
can be found in the LICENSE file. Software distributed under The | ||
MIT License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
OR CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/vouch/vouch-proxy/pkg/cfg" | ||
) | ||
|
||
func TestCallbackHandlerDocumentRoot(t *testing.T) { | ||
handlerL := http.HandlerFunc(LoginHandler) | ||
handlerA := http.HandlerFunc(CallbackHandler) | ||
|
||
tests := []struct { | ||
name string | ||
configFile string | ||
wantcode int | ||
}{ | ||
{"should have URL that begins with DocumentRoot", "/config/testing/handler_login_url_document_root.yml", http.StatusFound}, | ||
{"should have URL that does not begin with DocumentRoot", "/config/testing/handler_login_url.yml", http.StatusFound}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
setUp(tt.configFile) | ||
|
||
// first make a request of /login to set the session cookie | ||
reqLogin, err := http.NewRequest("GET", cfg.Cfg.DocumentRoot+"/login?url=http://myapp.example.com/logout", nil) | ||
reqLogin.Header.Set("Host", "my.example.com") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
rrL := httptest.NewRecorder() | ||
handlerL.ServeHTTP(rrL, reqLogin) | ||
|
||
// grab the state from the session cookie to | ||
session, err := sessstore.Get(reqLogin, cfg.Cfg.Session.Name) | ||
state := session.Values["state"].(string) | ||
|
||
// now mimic an IdP returning the state variable back to us | ||
reqAuth, err := http.NewRequest("GET", cfg.Cfg.DocumentRoot+"/auth?state="+state, nil) | ||
reqAuth.Header.Set("Host", "my.example.com") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// transfer the cookie from rrL to reqAuth | ||
rrA := httptest.NewRecorder() | ||
|
||
handlerA.ServeHTTP(rrA, reqAuth) | ||
if rrA.Code != tt.wantcode { | ||
t.Errorf("LoginHandler() status = %v, want %v", rrA.Code, tt.wantcode) | ||
} | ||
|
||
// confirm the requst to $DocumentRoot/auth is redirected to $DocumentRoot/auth/$state | ||
redirectURL, err := url.Parse(rrA.Header()["Location"][0]) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, fmt.Sprintf("%s/auth/%s/", cfg.Cfg.DocumentRoot, state), redirectURL.Path) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func TestAuthStateHandler(t *testing.T) { | ||
type args struct { | ||
w http.ResponseWriter | ||
r *http.Request | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
// TODO: Add test cases. | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
AuthStateHandler(tt.args.w, tt.args.r) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.