Skip to content

Commit 56dd586

Browse files
committed
Empty raw data in steam provider
1 parent 4929279 commit 56dd586

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

providers/steam/steam.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ func buildUserObject(r io.Reader, u goth.User) (goth.User, error) {
185185
u.Location = "No location is provided by the Steam API"
186186
}
187187

188+
// Set raw data
189+
b, err := json.Marshal(&player)
190+
if err != nil {
191+
return u, err
192+
}
193+
194+
err = json.Unmarshal(b, &u.RawData)
195+
if err != nil {
196+
return u, err
197+
}
198+
188199
return u, nil
189200
}
190201

providers/steam/steam_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package steam_test
22

33
import (
4+
"fmt"
5+
"net/http"
6+
"net/http/httptest"
7+
"net/url"
48
"os"
59
"testing"
610

@@ -50,6 +54,79 @@ func Test_SessionFromJSON(t *testing.T) {
5054
a.Equal(s.ResponseNonce, "2016-03-13T16:56:30ZJ8tlKVquwHi9ZSPV4ElU5PY2dmI=")
5155
}
5256

57+
func Test_FetchUser(t *testing.T) {
58+
apiUserSummaryPath := "/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s"
59+
60+
t.Parallel()
61+
a := assert.New(t)
62+
p := provider()
63+
session, err := p.UnmarshalSession(`{"AuthURL":"https://steamcommunity.com/openid/login?openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.realm=%3A%2F%2F&openid.return_to=%2Ffoo","SteamID":"1234567890","CallbackURL":"http://localhost:3030/","ResponseNonce":"2016-03-13T16:56:30ZJ8tlKVquwHi9ZSPV4ElU5PY2dmI="}`)
64+
a.NoError(err)
65+
66+
expectedPath := fmt.Sprintf(apiUserSummaryPath, p.APIKey, "1234567890")
67+
68+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
69+
a.Equal("application/json", r.Header.Get("Accept"))
70+
a.Equal(http.MethodGet, r.Method)
71+
a.Equal(expectedPath, r.URL.RequestURI())
72+
w.Write([]byte(testUserSummaryBody))
73+
}))
74+
defer ts.Close()
75+
76+
p.HTTPClient = ts.Client()
77+
p.HTTPClient.Transport = &httpTestTransport{server: ts}
78+
79+
user, err := p.FetchUser(session)
80+
a.NoError(err)
81+
a.Equal("76561197960435530", user.UserID)
82+
a.Equal("Robin", user.NickName)
83+
a.Equal("Robin Walker", user.Name)
84+
a.Equal("https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg", user.AvatarURL)
85+
a.Equal("No email is provided by the Steam API", user.Email)
86+
a.Equal("No description is provided by the Steam API", user.Description)
87+
a.Equal("WA, US", user.Location)
88+
a.Len(user.RawData, 6)
89+
a.Equal("76561197960435530", user.RawData["steamid"])
90+
a.Equal("Robin", user.RawData["personaname"])
91+
a.Equal("Robin Walker", user.RawData["realname"])
92+
a.Equal("https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg", user.RawData["avatarfull"])
93+
a.Equal("US", user.RawData["loccountrycode"])
94+
a.Equal("WA", user.RawData["locstatecode"])
95+
}
96+
5397
func provider() *steam.Provider {
5498
return steam.New(os.Getenv("STEAM_KEY"), "/foo")
5599
}
100+
101+
type httpTestTransport struct {
102+
server *httptest.Server
103+
}
104+
105+
func (t *httpTestTransport) RoundTrip(req *http.Request) (*http.Response, error) {
106+
uri, err := url.Parse(t.server.URL)
107+
if err != nil {
108+
return nil, err
109+
}
110+
111+
req.URL.Scheme = uri.Scheme
112+
req.URL.Host = uri.Host
113+
114+
return http.DefaultTransport.RoundTrip(req)
115+
}
116+
117+
// Extracted from: https://developer.valvesoftware.com/wiki/Steam_Web_API
118+
var testUserSummaryBody = `{
119+
"response": {
120+
"players": [
121+
{
122+
"steamid": "76561197960435530",
123+
"personaname": "Robin",
124+
"realname": "Robin Walker",
125+
"avatarfull": "https://avatars.steamstatic.com/81b5478529dce13bf24b55ac42c1af7058aaf7a9_full.jpg",
126+
"loccountrycode": "US",
127+
"locstatecode": "WA"
128+
}
129+
]
130+
131+
}
132+
}`

0 commit comments

Comments
 (0)