auth

Paddy 2014-07-18

0:7a6f64db7246 Go to Latest

auth/info_test.go

Start rewriting the repo. This code originally was a carbon copy of https://github.com/RangelReale/osin, but I am methodically stripping out the extensible nature of it for a simpler interface, while simultaneously bringing the style into line with the Ducky style.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/info_test.go	Fri Jul 18 07:13:22 2014 -0400
     1.3 @@ -0,0 +1,42 @@
     1.4 +package oauth2
     1.5 +
     1.6 +import (
     1.7 +	"net/http"
     1.8 +	"net/url"
     1.9 +	"testing"
    1.10 +)
    1.11 +
    1.12 +func TestInfo(t *testing.T) {
    1.13 +	sconfig := NewServerConfig()
    1.14 +	server := NewServer(sconfig, NewTestingStorage())
    1.15 +	resp := server.NewResponse()
    1.16 +
    1.17 +	req, err := http.NewRequest("GET", "http://localhost:14000/appauth", nil)
    1.18 +	if err != nil {
    1.19 +		t.Fatal(err)
    1.20 +	}
    1.21 +	req.Form = make(url.Values)
    1.22 +	req.Form.Set("code", "9999")
    1.23 +
    1.24 +	if ar := server.HandleInfoRequest(resp, req); ar != nil {
    1.25 +		server.FinishInfoRequest(resp, req, ar)
    1.26 +	}
    1.27 +
    1.28 +	//fmt.Printf("%+v", resp)
    1.29 +
    1.30 +	if resp.IsError && resp.InternalError != nil {
    1.31 +		t.Fatalf("Error in response: %s", resp.InternalError)
    1.32 +	}
    1.33 +
    1.34 +	if resp.IsError {
    1.35 +		t.Fatalf("Should not be an error")
    1.36 +	}
    1.37 +
    1.38 +	if resp.Type != DATA {
    1.39 +		t.Fatalf("Response should be data")
    1.40 +	}
    1.41 +
    1.42 +	if d := resp.Output["access_token"]; d != "9999" {
    1.43 +		t.Fatalf("Unexpected authorization code: %s", d)
    1.44 +	}
    1.45 +}