Skip to content

Commit

Permalink
testutil: just add new function to be used for tests
Browse files Browse the repository at this point in the history
To create keys based on other usernames without using environment
variables.
  • Loading branch information
fatih committed Mar 24, 2015
1 parent a170f4b commit 77b5c02
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ import (
// kontrol.go) If the host does not have a kite.key file kite.New() panics.
// This is a helper to put a fake key on it's location.
func NewKiteKey() *jwt.Token {
return newKiteKey("")
}

// NewKiteKeyUsername is like NewKiteKey() but it uses the given username
// instead of using the "testuser" name
func NewKiteKeyUsername(username string) *jwt.Token {
return newKiteKey(username)
}

func newKiteKey(username string) *jwt.Token {
tknID, err := uuid.NewV4()
if err != nil {
panic(err)
Expand All @@ -27,7 +37,10 @@ func NewKiteKey() *jwt.Token {
panic(err)
}

username := "testuser"
if username == "" {
username = "testuser"
}

if testuser := os.Getenv("TESTKEY_USERNAME"); testuser != "" {
username = testuser
}
Expand All @@ -51,6 +64,7 @@ func NewKiteKey() *jwt.Token {

token.Valid = true
return token

}

func NewConfig() *config.Config {
Expand Down

0 comments on commit 77b5c02

Please sign in to comment.