55 "io/ioutil"
66 "os"
77 "testing"
8+ "time"
89
910 _ "github.com/jinzhu/gorm/dialects/sqlite" // sql driver
1011
@@ -48,6 +49,7 @@ func (s *Suite) TearDownSuite(c *check.C) {
4849
4950func (* Suite ) TestCreatePreAuthKey (c * check.C ) {
5051 _ , err := h .CreatePreAuthKey ("bogus" , true , nil )
52+
5153 c .Assert (err , check .NotNil )
5254
5355 n , err := h .CreateNamespace ("test" )
@@ -73,3 +75,22 @@ func (*Suite) TestCreatePreAuthKey(c *check.C) {
7375 // Make sure the Namespace association is populated
7476 c .Assert ((* keys )[0 ].Namespace .Name , check .Equals , n .Name )
7577}
78+
79+ func (* Suite ) TestExpiredPreAuthKey (c * check.C ) {
80+ n , err := h .CreateNamespace ("test2" )
81+ c .Assert (err , check .IsNil )
82+
83+ now := time .Now ()
84+ pak , err := h .CreatePreAuthKey (n .Name , true , & now )
85+ c .Assert (err , check .IsNil )
86+
87+ p , err := h .checkKeyValidity (pak .Key )
88+ c .Assert (err , check .Equals , errorAuthKeyExpired )
89+ c .Assert (p , check .IsNil )
90+ }
91+
92+ func (* Suite ) TestPreAuthKeyDoesNotExist (c * check.C ) {
93+ p , err := h .checkKeyValidity ("potatoKey" )
94+ c .Assert (err , check .Equals , errorAuthKeyNotFound )
95+ c .Assert (p , check .IsNil )
96+ }
0 commit comments