-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #104 This is a regression brought on by recent refactorings. The new functionality is more robust in that l2met no longer cares whether you have a user:password format of decoded authorization. It will take everything up to and excluding the `:`.
- Loading branch information
1 parent
5ee91ed
commit 27b6331
Showing
4 changed files
with
43 additions
and
28 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
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 |
---|---|---|
|
@@ -8,23 +8,38 @@ import ( | |
"testing" | ||
) | ||
|
||
type authTest struct { | ||
input string | ||
output string | ||
} | ||
|
||
var authTests = []authTest{ | ||
{ | ||
"user:password", | ||
"user:password", | ||
}, | ||
} | ||
|
||
func TestAuth(t *testing.T) { | ||
for _, ts := range authTests { | ||
testEncryptDecrypt(t, ts) | ||
} | ||
} | ||
|
||
func testEncryptDecrypt(t *testing.T, ts authTest) { | ||
if len(keys) == 0 { | ||
t.Fatalf("Must set $SECRETS\n") | ||
} | ||
|
||
var b bytes.Buffer | ||
r, err := http.NewRequest("GET", "http://does-not-matter.com", &b) | ||
if err != nil { | ||
t.Error(err) | ||
t.Fatalf("error=%s\n", err) | ||
} | ||
|
||
expectedUser := "[email protected]" | ||
expectedPass := "abc123" | ||
tok, err := fernet.EncryptAndSign([]byte(expectedUser+":"+expectedPass), | ||
keys[0]) | ||
tok, err := fernet.EncryptAndSign([]byte(ts.input), keys[0]) | ||
if err != nil { | ||
t.Error(err) | ||
t.Fatalf("error=%s\n", err) | ||
} | ||
r.Header.Set("Authorization", | ||
"Basic "+base64.StdEncoding.EncodeToString(tok)) | ||
|
@@ -34,16 +49,12 @@ func TestAuth(t *testing.T) { | |
t.Fatalf("error=%s\n", err) | ||
} | ||
|
||
actualUser, actualPass, err := Decrypt(parseRes) | ||
actualOutput, err := Decrypt(parseRes) | ||
if err != nil { | ||
t.Fatalf("error=%s\n", err) | ||
} | ||
|
||
if actualUser != expectedUser { | ||
t.Fatalf("actual=%q expected=%q\n", actualUser, expectedUser) | ||
} | ||
|
||
if actualPass != expectedPass { | ||
t.Fatalf("actual=%q expected=%q\n", actualPass, expectedPass) | ||
if actualOutput != ts.output { | ||
t.Fatalf("actual=%q expected=%q\n", actualOutput, ts.output) | ||
} | ||
} |
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