This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
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
2 changed files
with
48 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,13 @@ | ||
package push | ||
|
||
import "encoding/hex" | ||
|
||
// IsDeviceTokenValid checks if s is a hexadecimal token of the correct length. | ||
func IsDeviceTokenValid(s string) bool { | ||
// TODO: In 2016, they may be growing up to 100 bytes (200 hexadecimal digits). | ||
if len(s) != 64 { | ||
return false | ||
} | ||
_, err := hex.DecodeString(s) | ||
return err == nil | ||
} |
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,35 @@ | ||
package push_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/RobotsAndPencils/buford/push" | ||
) | ||
|
||
func TestInvalidDeviceTokens(t *testing.T) { | ||
tokens := []string{ | ||
"invalid-token", | ||
"f00f", | ||
"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl", | ||
"50c4afb5 9197d2ba d1794be4 e63f2532 ee18c660 0ee655fa 38b0b380 94fd8847", | ||
"<50c4afb5 9197d2ba d1794be4 e63f2532 ee18c660 0ee655fa 38b0b380 94fd8847>", | ||
} | ||
|
||
for _, token := range tokens { | ||
if push.IsDeviceTokenValid(token) { | ||
t.Errorf("Expected device token %q to be invalid.", token) | ||
} | ||
} | ||
} | ||
|
||
func TestValidDeviceToken(t *testing.T) { | ||
tokens := []string{ | ||
"c2732227a1d8021cfaf781d71fb2f908c61f5861079a00954a5453f1d0281433", | ||
} | ||
|
||
for _, token := range tokens { | ||
if !push.IsDeviceTokenValid(token) { | ||
t.Errorf("Expected device token %q to be valid.", token) | ||
} | ||
} | ||
} |