auth

Paddy 2015-03-24 Parent:de5e09680f6b Child:202e991accc2

153:3e8964a914ef Go to Latest

auth/authd/server.go

Fix tests for scopeStore. Update all our tests to use the PG_TEST_DB environment variable if set, and use that to control whether or not the postgres tests get run. testing.Short() just wasn't working. Update ErrScopeNotFound and ErrScopeAlreadyExists to be variables instead of types, because PostgreSQL (annoyingly) offers no way to determine which specific row insertion caused the problem, and I anticipate this being a problem that is ongoing. So it's really just not worth it. Stop getScopes from returning an ErrScopeNotFound. Let's return what we find, and let the absence of what we didn't find speak for itself. Fix an error with generating the SQL for the postgres.createScopes call. We used to generate it in a way that was invalid (not joining values with ",") when more than one set of values was supplied. Hooray, testing! Update the postgres scopeStore to return ErrScopeNotFound and ErrScopeAlreadyExists errors, as appropriate. Update our tests to reflect that ErrScopeNotFound and ErrScopeAlreadyExists are now variables, not types.

History
paddy@100 1 package main
paddy@100 2
paddy@100 3 import (
paddy@100 4 "html/template"
paddy@100 5 "log"
paddy@100 6 "net/http"
paddy@100 7
paddy@107 8 "code.secondbit.org/auth.hg"
paddy@100 9 "github.com/gorilla/mux"
paddy@100 10 )
paddy@100 11
paddy@100 12 func main() {
paddy@151 13 log.SetFlags(log.LstdFlags | log.Llongfile)
paddy@149 14 p, err := auth.NewPostgres("dbname=testdb sslmode=disable")
paddy@149 15 if err != nil {
paddy@149 16 panic(err)
paddy@149 17 }
paddy@100 18 store := auth.NewMemstore()
paddy@149 19 if err != nil {
paddy@149 20 panic(err)
paddy@149 21 }
paddy@100 22 config := auth.Config{
paddy@151 23 ClientStore: &p,
paddy@100 24 AuthCodeStore: store,
paddy@149 25 ProfileStore: &p,
paddy@100 26 TokenStore: store,
paddy@100 27 SessionStore: store,
paddy@152 28 ScopeStore: &p,
paddy@100 29 Template: template.Must(template.New("base").ParseGlob("./templates/*.gotmpl")),
paddy@100 30 LoginURI: "/login",
paddy@100 31 }
paddy@149 32 err = config.Init()
paddy@106 33 if err != nil {
paddy@106 34 log.Fatal(err)
paddy@106 35 }
paddy@100 36 context, err := auth.NewContext(config)
paddy@100 37 if err != nil {
paddy@100 38 panic(err)
paddy@100 39 }
paddy@149 40 err = context.CreateScopes([]auth.Scope{
paddy@149 41 {ID: "testscope", Name: "Test Scope"},
paddy@149 42 })
paddy@152 43 if err != nil {
paddy@152 44 panic(err)
paddy@152 45 }
paddy@100 46
paddy@100 47 router := mux.NewRouter()
paddy@100 48 auth.RegisterOAuth2(router, context)
paddy@100 49 auth.RegisterSessionHandlers(router, context)
paddy@106 50 auth.RegisterProfileHandlers(router, context)
paddy@108 51 auth.RegisterClientHandlers(router, context)
paddy@100 52 http.Handle("/", router)
paddy@100 53 log.Fatal(http.ListenAndServe(":8080", nil))
paddy@100 54 }