Skip to content

Commit

Permalink
Merge pull request #18 from davseby/master
Browse files Browse the repository at this point in the history
Fix session IsValid method to check for nil user agent
  • Loading branch information
swithek authored Aug 26, 2021
2 parents 6a8a150 + 814ed49 commit 346234b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func (s Session) IsValid(r *http.Request) bool {

os := true
if s.Agent.OS != "" {
os = s.Agent.OS == a.OS
os = a != nil && s.Agent.OS == a.OS
}

browser := true
if s.Agent.Browser != "" {
browser = s.Agent.Browser == a.Name
browser = a != nil && s.Agent.Browser == a.Name
}

return ip && os && browser
Expand Down
9 changes: 9 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func TestIsValid(t *testing.T) {
Session: ses,
Res: false,
},
"Empty User-Agent": {
Req: func() *http.Request {
creq := httptest.NewRequest("GET", "http://example.com/", nil)
creq.RemoteAddr = req.RemoteAddr
return creq
}(),
Session: ses,
Res: false,
},
"Invalid User-Agent browser": {
Req: func() *http.Request {
creq := httptest.NewRequest("GET", "http://example.com/", nil)
Expand Down

0 comments on commit 346234b

Please sign in to comment.