forked from bobziuchkovski/digest
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
25 additions
and
41 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 |
---|---|---|
|
@@ -33,28 +33,23 @@ var cnonce = "0a4f113b" | |
func TestH(t *testing.T) { | ||
testCases := map[string]map[string]string{ | ||
"MD5": { | ||
"r1": "Mufasa:[email protected]:Circle Of Life", | ||
"r2": "GET:/dir/index.html", | ||
"r1": "Mufasa:[email protected]:Circle Of Life", | ||
"r2": "GET:/dir/index.html", | ||
"expected_r1": "939e7578ed9e3c518a452acee763bce9", | ||
"expected_r2": "39aff3a2bab6126f332b942af96d3366", | ||
"expected_r3": "6629fae49393a05397450978507c4ef1", | ||
}, | ||
"SHA-256": { | ||
"r1": "Mufasa:[email protected]:Circle Of Life", | ||
"r2": "GET:/dir/index.html", | ||
"r1": "Mufasa:[email protected]:Circle Of Life", | ||
"r2": "GET:/dir/index.html", | ||
"expected_r1": "3ba6cd94661c5ef34598040c868f13b8775df29109986be50ad35ae537dd3aa4", | ||
"expected_r2": "9a3fdae9a622fe8de177c24fa9c070f2b181ec85e15dcbdc32e10c82ad450b04", | ||
"expected_r3": "5abdd07184ba512a22c53f41470e5eea7dcaa3a93a59b630c13dfe0a5dc6e38b", | ||
}, | ||
} | ||
for testType, values := range testCases { | ||
t.Run(testType, func(t *testing.T) { | ||
var hashingFunc hashingFunc | ||
if testType == "MD5" { | ||
hashingFunc = md5.New | ||
} else if testType == "SHA-256" { | ||
hashingFunc = sha256.New | ||
} | ||
hashingFunc := testHashingFunc(testType) | ||
r1 := h(values["r1"], hashingFunc) | ||
if r1 != values["expected_r1"] { | ||
t.Errorf("expected=%s, but got=%s\n", values["expected_r1"], r1) | ||
|
@@ -74,25 +69,20 @@ func TestH(t *testing.T) { | |
func TestKd(t *testing.T) { | ||
testCases := map[string]map[string]string{ | ||
"MD5": { | ||
"secret": "939e7578ed9e3c518a452acee763bce9", | ||
"data": "dcd98b7102dd2f0e8b11d0f600bfb0c093:00000001:0a4f113b:auth:39aff3a2bab6126f332b942af96d3366", | ||
"secret": "939e7578ed9e3c518a452acee763bce9", | ||
"data": "dcd98b7102dd2f0e8b11d0f600bfb0c093:00000001:0a4f113b:auth:39aff3a2bab6126f332b942af96d3366", | ||
"expected": "6629fae49393a05397450978507c4ef1", | ||
}, | ||
"SHA-256": { | ||
"secret": "939e7578ed9e3c518a452acee763bce9", | ||
"data": "dcd98b7102dd2f0e8b11d0f600bfb0c093:00000001:0a4f113b:auth:39aff3a2bab6126f332b942af96d3366", | ||
"secret": "939e7578ed9e3c518a452acee763bce9", | ||
"data": "dcd98b7102dd2f0e8b11d0f600bfb0c093:00000001:0a4f113b:auth:39aff3a2bab6126f332b942af96d3366", | ||
"expected": "ca165e8478c14bd2a5c64cc86ffe17c277ee2cff3e98c330ee5565e8e206ca3e", | ||
}, | ||
} | ||
for testType, values := range testCases { | ||
t.Run(testType, func(t *testing.T) { | ||
var hashingFunc hashingFunc | ||
if testType == "MD5" { | ||
hashingFunc = md5.New | ||
} else if testType == "SHA-256" { | ||
hashingFunc = sha256.New | ||
} | ||
if r1 := kd(values["secret"],values["data"], hashingFunc); r1 != values["expected"] { | ||
hashingFunc := testHashingFunc(testType) | ||
if r1 := kd(values["secret"], values["data"], hashingFunc); r1 != values["expected"] { | ||
t.Errorf("expected=%s, but got=%s\n", values["expected"], r1) | ||
} | ||
}) | ||
|
@@ -110,12 +100,7 @@ func TestHa1(t *testing.T) { | |
} | ||
for testType, values := range testCases { | ||
t.Run(testType, func(t *testing.T) { | ||
var hashingFunc hashingFunc | ||
if testType == "MD5" { | ||
hashingFunc = md5.New | ||
} else if testType == "SHA-256" { | ||
hashingFunc = sha256.New | ||
} | ||
hashingFunc := testHashingFunc(testType) | ||
cred := &credentials{ | ||
Username: "Mufasa", | ||
Realm: "[email protected]", | ||
|
@@ -128,7 +113,7 @@ func TestHa1(t *testing.T) { | |
password: "Circle Of Life", | ||
impl: hashingFunc, | ||
} | ||
if r1 := cred.ha1(); r1 != values["expected"] { | ||
if r1 := cred.ha1(); r1 != values["expected"] { | ||
t.Errorf("expected=%s, but got=%s\n", values["expected"], r1) | ||
} | ||
}) | ||
|
@@ -146,12 +131,7 @@ func TestHa2(t *testing.T) { | |
} | ||
for testType, values := range testCases { | ||
t.Run(testType, func(t *testing.T) { | ||
var hashingFunc hashingFunc | ||
if testType == "MD5" { | ||
hashingFunc = md5.New | ||
} else if testType == "SHA-256" { | ||
hashingFunc = sha256.New | ||
} | ||
hashingFunc := testHashingFunc(testType) | ||
cred := &credentials{ | ||
Username: "Mufasa", | ||
Realm: "[email protected]", | ||
|
@@ -164,7 +144,7 @@ func TestHa2(t *testing.T) { | |
password: "Circle Of Life", | ||
impl: hashingFunc, | ||
} | ||
if r1 := cred.ha2(); r1 != values["expected"] { | ||
if r1 := cred.ha2(); r1 != values["expected"] { | ||
t.Errorf("expected=%s, but got=%s\n", values["expected"], r1) | ||
} | ||
}) | ||
|
@@ -182,12 +162,7 @@ func TestResp(t *testing.T) { | |
} | ||
for testType, values := range testCases { | ||
t.Run(testType, func(t *testing.T) { | ||
var hashingFunc hashingFunc | ||
if testType == "MD5" { | ||
hashingFunc = md5.New | ||
} else if testType == "SHA-256" { | ||
hashingFunc = sha256.New | ||
} | ||
hashingFunc := testHashingFunc(testType) | ||
cred := &credentials{ | ||
Username: "Mufasa", | ||
Realm: "[email protected]", | ||
|
@@ -206,3 +181,12 @@ func TestResp(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func testHashingFunc(testType string) hashingFunc { | ||
if testType == "MD5" { | ||
return md5.New | ||
} else if testType == "SHA-256" { | ||
return sha256.New | ||
} | ||
return nil | ||
} |