forked from remote/oauth2
token: extra numeric values + test TokenType case
+ Added tests for TokenType by checking case. + Added numeric conversion for float and integer like values from token.Extra. Change-Id: I0909a4458ed58e33428afbf40478a668d150dda7 Reviewed-on: https://go-review.googlesource.com/15156 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
committed by
Andrew Gerrand
parent
3cab960fb9
commit
2fbf3d7329
@@ -11,6 +11,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
@@ -170,6 +171,54 @@ func TestExchangeRequest_JSONResponse(t *testing.T) {
|
||||
if scope != "user" {
|
||||
t.Errorf("Unexpected value for scope: %v", scope)
|
||||
}
|
||||
expiresIn := tok.Extra("expires_in")
|
||||
if expiresIn != float64(86400) {
|
||||
t.Errorf("Unexpected non-numeric value for expires_in: %v", expiresIn)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtraValueRetrieval(t *testing.T) {
|
||||
values := url.Values{}
|
||||
|
||||
kvmap := map[string]string{
|
||||
"scope": "user", "token_type": "bearer", "expires_in": "86400.92",
|
||||
"server_time": "1443571905.5606415", "referer_ip": "10.0.0.1",
|
||||
"etag": "\"afZYj912P4alikMz_P11982\"", "request_id": "86400",
|
||||
"untrimmed": " untrimmed ",
|
||||
}
|
||||
|
||||
for key, value := range kvmap {
|
||||
values.Set(key, value)
|
||||
}
|
||||
|
||||
tok := Token{
|
||||
raw: values,
|
||||
}
|
||||
|
||||
scope := tok.Extra("scope")
|
||||
if scope != "user" {
|
||||
t.Errorf("Unexpected scope %v wanted \"user\"", scope)
|
||||
}
|
||||
serverTime := tok.Extra("server_time")
|
||||
if serverTime != 1443571905.5606415 {
|
||||
t.Errorf("Unexpected non-float64 value for server_time: %v", serverTime)
|
||||
}
|
||||
refererIp := tok.Extra("referer_ip")
|
||||
if refererIp != "10.0.0.1" {
|
||||
t.Errorf("Unexpected non-string value for referer_ip: %v", refererIp)
|
||||
}
|
||||
expires_in := tok.Extra("expires_in")
|
||||
if expires_in != 86400.92 {
|
||||
t.Errorf("Unexpected value for expires_in, wanted 86400 got %v", expires_in)
|
||||
}
|
||||
requestId := tok.Extra("request_id")
|
||||
if requestId != int64(86400) {
|
||||
t.Errorf("Unexpected non-int64 value for request_id: %v", requestId)
|
||||
}
|
||||
untrimmed := tok.Extra("untrimmed")
|
||||
if untrimmed != " untrimmed " {
|
||||
t.Errorf("Unexpected value for untrimmed, got %q expected \" untrimmed \"", untrimmed)
|
||||
}
|
||||
}
|
||||
|
||||
const day = 24 * time.Hour
|
||||
|
||||
Reference in New Issue
Block a user