-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(coverage): Add more tests on pkce package
- Loading branch information
NORMAND, Thibault
committed
Jan 11, 2018
1 parent
2a908a1
commit d724a36
Showing
4 changed files
with
144 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pkce | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsValid(t *testing.T) { | ||
for k, c := range []struct { | ||
given string | ||
valid bool | ||
}{ | ||
{ | ||
given: "", | ||
valid: false, | ||
}, | ||
{ // Too short | ||
given: "tFQvz4e1umkzHgeWAR4lGOy7mI4dbCrzPwvYlqlxpx", | ||
valid: false, | ||
}, | ||
{ | ||
given: "tFQvz4e1umkzHgeWAR4lGOy7mI4dbCrzPwvYlqlxpx6", | ||
valid: true, | ||
}, | ||
{ | ||
given: "pq6eJXUdXhEDNqwDHbFOwx5BGtYgKWXdhyMLEHsOLPBvwLhrRCyBmVWfB4x6Nkd4CXyxLAr1tnfCjs9boH4UrQeFkkoNKXLllJhKNs9mvleFWw6TUsF04WDrLA23xBod", | ||
valid: true, | ||
}, | ||
{ // To long | ||
given: "pq6eJXUdXhEDNqwDHbFOwx5BGtYgKWXdhyMLEHsOLPBvwLhrRCyBmVWfB4x6Nkd4CXyxLAr1tnfCjs9boH4UrQeFkkoNKXLllJhKNs9mvleFWw6TUsF04WDrLA23xBod0", | ||
valid: false, | ||
}, | ||
} { | ||
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { | ||
valid := IsValid(c.given) | ||
assert.Equal(t, c.valid, valid, fmt.Sprintf("Should be as expected, result: %t, expected: %t", valid, c.valid)) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package pkce | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPlainVerfier(t *testing.T) { | ||
// Instanciate the verifier | ||
v := &plainVerifier{} | ||
require.NotNil(t, v) | ||
require.Equal(t, Plain, v.String()) | ||
|
||
for k, c := range []struct { | ||
given string | ||
expected string | ||
valid bool | ||
}{ | ||
{ | ||
given: "123456", | ||
expected: "123456", | ||
valid: true, | ||
}, | ||
{ | ||
given: "123456", | ||
expected: "12345", | ||
valid: false, | ||
}, | ||
{ | ||
given: "12345", | ||
expected: "123456", | ||
valid: false, | ||
}, | ||
{ // Useless test, but codeverifier is not size limited by the verifier | ||
given: "", | ||
expected: "", | ||
valid: true, | ||
}, | ||
} { | ||
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { | ||
valid := v.Compare(c.given, c.expected) | ||
assert.Equal(t, c.valid, valid, fmt.Sprintf("Should be as expected, result: %t, expected: %t", valid, c.valid)) | ||
}) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pkce | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSha256Verfier(t *testing.T) { | ||
// Instanciate the verifier | ||
v := &s256Verifier{} | ||
require.NotNil(t, v) | ||
require.Equal(t, S256, v.String()) | ||
|
||
for k, c := range []struct { | ||
given string | ||
expected string | ||
valid bool | ||
}{ | ||
{ | ||
given: "12345678", | ||
expected: "73l8gRjwLftklgfdXT-MdiMEjJwGPVMsyVxe16iYpk8", | ||
valid: true, | ||
}, | ||
} { | ||
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { | ||
valid := v.Compare(c.given, c.expected) | ||
assert.Equal(t, c.valid, valid, fmt.Sprintf("Should be as expected, result: %t, expected: %t", valid, c.valid)) | ||
}) | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package pkce | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVerifier(t *testing.T) { | ||
require.NotNil(t, GetVerifier(Plain)) | ||
require.NotNil(t, GetVerifier(S256)) | ||
require.Nil(t, GetVerifier("invalid-verifier-method")) | ||
} | ||
|
||
func TestVerifierRegistration(t *testing.T) { | ||
require.NotNil(t, GetVerifier(Plain)) | ||
require.Panics(t, func() { | ||
RegisterVerifier(Plain, &plainVerifier{}) | ||
}) | ||
} |