From 8a3442fb083f68c03948c257ab04e66c9ae1476a Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Tue, 26 May 2015 13:18:57 -0400 Subject: [PATCH 1/3] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37ac480..9463fd9 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# fakecas +# Fake CAS + +Download the binary from [here](https://github.com/CenterForOpenScience/fakecas/releases/download/0.1.0/fakecas) + +```bash +cd ~/Downloads # cd to where you downloaded the file to +chmod +x fakecas # Make the server executable +./fakecas # Run the server +``` From 25ea06114362df6a76dc9f33f1596e3904984154 Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Mon, 1 Jun 2015 19:57:35 -0400 Subject: [PATCH 2/3] Allow configuration via commandline params --- fakecas.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/fakecas.go b/fakecas.go index 41813d0..da063d7 100644 --- a/fakecas.go +++ b/fakecas.go @@ -3,6 +3,8 @@ package main import ( "encoding/json" "encoding/xml" + "flag" + "fmt" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "log" @@ -43,12 +45,28 @@ type ServiceResponse struct { UserName string `xml:"cas:authenticationSuccess>cas:attributes>username"` } +var ( + host = flag.String("host", "localhost:8080", "The host to bind to") + databasename = flag.String("dbname", "osf20130903", "The name of your OSF database") + databaseaddress = flag.String("dbaddress", "localhost:27017", "The address of your mongodb. ie: localhost:27017") +) + func main() { + flag.Parse() + http.HandleFunc("/login", login) http.HandleFunc("/logout", logout) http.HandleFunc("/oauth2/profile", oauth) http.HandleFunc("/p3/serviceValidate", serviceValidate) - http.ListenAndServe("localhost:8080", nil) + + fmt.Println("Expecting database", *databasename, " to be running at", *databaseaddress) + fmt.Println("Listening on", *host) + + err := http.ListenAndServe(*host, nil) + + if err != nil { + log.Fatal("ListenAndServe: ", err) + } } func login(w http.ResponseWriter, r *http.Request) { @@ -62,27 +80,30 @@ func login(w http.ResponseWriter, r *http.Request) { query.Set("ticket", r.FormValue("username")) redir.RawQuery = query.Encode() + fmt.Println("Logging in and redirecting to", redir) http.Redirect(w, r, redir.String(), http.StatusFound) } func logout(w http.ResponseWriter, r *http.Request) { + fmt.Println("Logging out and redirecting to", r.FormValue("service")) http.Redirect(w, r, r.FormValue("service"), http.StatusFound) } func serviceValidate(w http.ResponseWriter, r *http.Request) { - session, err := mgo.Dial("localhost:27017") + session, err := mgo.Dial(*databaseaddress) if err != nil { panic(err) } defer session.Close() - c := session.DB("osf20130903").C("user") + c := session.DB(*databasename).C("user") result := User{} err = c.Find(bson.M{"username": r.FormValue("ticket")}).One(&result) if err != nil { + fmt.Println("User", r.FormValue("ticket"), "not found.") http.NotFound(w, r) return } @@ -109,13 +130,13 @@ func serviceValidate(w http.ResponseWriter, r *http.Request) { func oauth(w http.ResponseWriter, r *http.Request) { - session, err := mgo.Dial("localhost:27017") + session, err := mgo.Dial(*databaseaddress) if err != nil { panic(err) } defer session.Close() - c := session.DB("osf20130903").C("user") + c := session.DB(*databasename).C("user") result := User{} err = c.Find(bson.M{"_id": strings.Replace(r.Header.Get("Authorization"), "Bearer ", "", 1)}).One(&result) From 8b2f3f7fd21024bd5a1c1555f612c5d45361e79d Mon Sep 17 00:00:00 2001 From: Chris Seto Date: Mon, 1 Jun 2015 20:00:30 -0400 Subject: [PATCH 3/3] Update readme --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9463fd9..7fb26b4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ # Fake CAS -Download the binary from [here](https://github.com/CenterForOpenScience/fakecas/releases/download/0.1.0/fakecas) +Download the binary from [here](https://github.com/CenterForOpenScience/fakecas/releases/download/0.2.0/fakecas) ```bash cd ~/Downloads # cd to where you downloaded the file to chmod +x fakecas # Make the server executable ./fakecas # Run the server + +./fakecas -h # Print possible configuration options +# Usage of ./fakecas: +# -dbaddress="localhost:27017": The address of your mongodb. ie: localhost:27017 +# -dbname="osf20130903": The name of your OSF database +# -host="localhost:8080": The host to bind to ```