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:
@@ -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")
|
||||
|
||||
@@ -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
|
||||
}{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user