@@ -24,6 +24,7 @@ import (
2424 "reflect"
2525 "strings"
2626 "testing"
27+ "time"
2728
2829 "firebase.google.com/go/internal"
2930
@@ -59,9 +60,10 @@ var testUser = &UserRecord{
5960 UID : "testuid" ,
6061 },
6162 },
63+ TokensValidAfterMillis : 1494364393000 ,
6264 UserMetadata : & UserMetadata {
63- CreationTimestamp : 1234567890 ,
64- LastLogInTimestamp : 1233211232 ,
65+ CreationTimestamp : 1234567890000 ,
66+ LastLogInTimestamp : 1233211232000 ,
6567 },
6668 CustomClaims : map [string ]interface {}{"admin" : true , "package" : "gold" },
6769}
@@ -496,6 +498,41 @@ func TestUpdateUser(t *testing.T) {
496498 }
497499 }
498500}
501+ func TestRevokeRefreshTokens (t * testing.T ) {
502+ resp := `{
503+ "kind": "identitytoolkit#SetAccountInfoResponse",
504+ "localId": "expectedUserID"
505+ }`
506+ s := echoServer ([]byte (resp ), t )
507+ defer s .Close ()
508+ before := time .Now ().Unix ()
509+ if err := s .Client .RevokeRefreshTokens (context .Background (), "some_uid" ); err != nil {
510+ t .Error (err )
511+ }
512+ after := time .Now ().Unix ()
513+
514+ req := & identitytoolkit.IdentitytoolkitRelyingpartySetAccountInfoRequest {}
515+ if err := json .Unmarshal (s .Rbody , & req ); err != nil {
516+ t .Error (err )
517+ }
518+ if req .ValidSince > after || req .ValidSince < before {
519+ t .Errorf ("validSince = %d, expecting time between %d and %d" , req .ValidSince , before , after )
520+ }
521+ }
522+
523+ func TestRevokeRefreshTokensInvalidUID (t * testing.T ) {
524+ resp := `{
525+ "kind": "identitytoolkit#SetAccountInfoResponse",
526+ "localId": "expectedUserID"
527+ }`
528+ s := echoServer ([]byte (resp ), t )
529+ defer s .Close ()
530+
531+ we := "uid must not be empty"
532+ if err := s .Client .RevokeRefreshTokens (context .Background (), "" ); err == nil || err .Error () != we {
533+ t .Errorf ("RevokeRefreshTokens(); err = %s; want err = %s" , err .Error (), we )
534+ }
535+ }
499536
500537func TestInvalidSetCustomClaims (t * testing.T ) {
501538 cases := []struct {
@@ -609,8 +646,8 @@ func TestMakeExportedUser(t *testing.T) {
609646 PasswordHash : "passwordhash" ,
610647 ValidSince : 1494364393 ,
611648 Disabled : false ,
612- CreatedAt : 1234567890 ,
613- LastLoginAt : 1233211232 ,
649+ CreatedAt : 1234567890000 ,
650+ LastLoginAt : 1233211232000 ,
614651 CustomAttributes : `{"admin": true, "package": "gold"}` ,
615652 ProviderUserInfo : []* identitytoolkit.UserInfoProviderUserInfo {
616653 {
@@ -637,7 +674,8 @@ func TestMakeExportedUser(t *testing.T) {
637674 }
638675 if ! reflect .DeepEqual (exported .UserRecord , want .UserRecord ) {
639676 // zero in
640- t .Errorf ("makeExportedUser() = %#v; want: %#v" , exported .UserRecord , want .UserRecord )
677+ t .Errorf ("makeExportedUser() = %#v; want: %#v \n (%#v)\n (%#v)" , exported .UserRecord , want .UserRecord ,
678+ exported .UserMetadata , want .UserMetadata )
641679 }
642680 if exported .PasswordHash != want .PasswordHash {
643681 t .Errorf ("PasswordHash = %q; want = %q" , exported .PasswordHash , want .PasswordHash )
@@ -690,8 +728,7 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
690728 case []byte :
691729 b = v
692730 default :
693- b , err = json .Marshal (resp )
694- if err != nil {
731+ if b , err = json .Marshal (resp ); err != nil {
695732 t .Fatal ("marshaling error" )
696733 }
697734 }
@@ -729,17 +766,17 @@ func echoServer(resp interface{}, t *testing.T) *mockAuthServer {
729766 }
730767 w .Header ().Set ("Content-Type" , "application/json" )
731768 w .Write (s .Resp )
732-
733769 })
734770 s .Srv = httptest .NewServer (handler )
735-
736771 conf := & internal.AuthConfig {
737772 Opts : []option.ClientOption {
738- option .WithTokenSource (& mockTokenSource {testToken }),
739- } ,
740- Version : testVersion ,
773+ option .WithTokenSource (& mockTokenSource {testToken })} ,
774+ ProjectID : "mock-project-id" ,
775+ Version : testVersion ,
741776 }
742- authClient , err := NewClient (context .Background (), conf )
777+
778+ authClient , err := NewClient (ctx , conf )
779+ authClient .ks = & fileKeySource {FilePath : "../testdata/public_certs.json" }
743780 if err != nil {
744781 t .Fatal (err )
745782 }
0 commit comments