This repository has been archived by the owner on Jan 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from 18F/access-token-refactor
Refactor pass_access_token changes from #80
- Loading branch information
Showing
7 changed files
with
149 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,6 @@ _testmain.go | |
*.exe | ||
dist | ||
.godeps | ||
|
||
# Editor swap/temp files | ||
.*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package main | |
import ( | ||
"crypto/aes" | ||
"github.com/bmizerany/assert" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
|
@@ -21,3 +22,54 @@ func TestEncodeAndDecodeAccessToken(t *testing.T) { | |
assert.NotEqual(t, access_token, encoded_token) | ||
assert.Equal(t, access_token, decoded_token) | ||
} | ||
|
||
func TestBuildCookieValueWithoutAccessToken(t *testing.T) { | ||
value, err := buildCookieValue("[email protected]", nil, "") | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "[email protected]", value) | ||
} | ||
|
||
func TestBuildCookieValueWithAccessTokenAndNilCipher(t *testing.T) { | ||
value, err := buildCookieValue("[email protected]", nil, | ||
"access token") | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "[email protected]", value) | ||
} | ||
|
||
func TestParseCookieValueWithoutAccessToken(t *testing.T) { | ||
email, user, access_token, err := parseCookieValue( | ||
"[email protected]", nil) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "[email protected]", email) | ||
assert.Equal(t, "michael.bland", user) | ||
assert.Equal(t, "", access_token) | ||
} | ||
|
||
func TestParseCookieValueWithAccessTokenAndNilCipher(t *testing.T) { | ||
email, user, access_token, err := parseCookieValue( | ||
"[email protected]|access_token", nil) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "[email protected]", email) | ||
assert.Equal(t, "michael.bland", user) | ||
assert.Equal(t, "", access_token) | ||
} | ||
|
||
func TestBuildAndParseCookieValueWithAccessToken(t *testing.T) { | ||
aes_cipher, err := aes.NewCipher([]byte("0123456789abcdef")) | ||
assert.Equal(t, nil, err) | ||
value, err := buildCookieValue("[email protected]", aes_cipher, | ||
"access_token") | ||
assert.Equal(t, nil, err) | ||
|
||
prefix := "[email protected]|" | ||
if !strings.HasPrefix(value, prefix) { | ||
t.Fatal("cookie value does not start with \"%s\": %s", | ||
prefix, value) | ||
} | ||
|
||
email, user, access_token, err := parseCookieValue(value, aes_cipher) | ||
assert.Equal(t, nil, err) | ||
assert.Equal(t, "[email protected]", email) | ||
assert.Equal(t, "michael.bland", user) | ||
assert.Equal(t, "access_token", access_token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters