Quick contexts additions (#739)

* Defining a concrete type for session tokens

* More rightish vc.IsLoggedIn()

* using type conversion instead of a method call

* include sessions in test viewer contexts
This commit is contained in:
Mike Arpaia
2017-01-09 08:10:02 -07:00
committed by GitHub
parent cc5aa3395d
commit a047ef2211
8 changed files with 68 additions and 25 deletions
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/kolide/kolide-ose/server/contexts/token"
"github.com/pkg/errors"
)
@@ -112,13 +113,13 @@ func (c *Conn) ReadJSONMessage() (*JSONMessage, error) {
// authData defines the data used to authenticate a Kolide frontend client over
// a websocket connection.
type authData struct {
Token string `json:"token"`
Token token.Token `json:"token"`
}
// ReadAuthToken reads from the websocket, returning an auth token embedded in
// a JSONMessage with type "auth" and data that can be unmarshalled to
// authData.
func (c *Conn) ReadAuthToken() (string, error) {
func (c *Conn) ReadAuthToken() (token.Token, error) {
msg, err := c.ReadJSONMessage()
if err != nil {
return "", errors.Wrap(err, "read auth token")
+2 -1
View File
@@ -10,6 +10,7 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/kolide/kolide-ose/server/contexts/token"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -238,7 +239,7 @@ func TestReadAuthToken(t *testing.T) {
var cases = []struct {
typ string
data authData
token string
token token.Token
err error
}{
{