GIDGoogleUserTest.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h"
  15. #import <XCTest/XCTest.h>
  16. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDProfileData.h"
  18. #import "GoogleSignIn/Sources/GIDAuthentication_Private.h"
  19. #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
  20. #import "GoogleSignIn/Tests/Unit/GIDProfileData+Testing.h"
  21. #import "GoogleSignIn/Tests/Unit/OIDAuthState+Testing.h"
  22. #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
  23. #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
  24. #import <AppAuth/OIDAuthState.h>
  25. @interface GIDGoogleUserTest : XCTestCase
  26. @end
  27. @implementation GIDGoogleUserTest
  28. #pragma mark - Tests
  29. - (void)testInitWithAuthState {
  30. OIDAuthState *authState = [OIDAuthState testInstance];
  31. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState
  32. profileData:[GIDProfileData testInstance]];
  33. GIDAuthentication *authentication =
  34. [[GIDAuthentication alloc] initWithAuthState:authState];
  35. XCTAssertEqualObjects(user.authentication, authentication);
  36. XCTAssertEqualObjects(user.grantedScopes, @[ OIDAuthorizationRequestTestingScope2 ]);
  37. XCTAssertEqualObjects(user.userID, kUserID);
  38. XCTAssertEqualObjects(user.hostedDomain, kHostedDomain);
  39. XCTAssertEqualObjects(user.serverAuthCode, kServerAuthCode);
  40. XCTAssertEqualObjects(user.profile, [GIDProfileData testInstance]);
  41. }
  42. - (void)testCoding {
  43. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:[OIDAuthState testInstance]
  44. profileData:[GIDProfileData testInstance]];
  45. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
  46. GIDGoogleUser *newUser = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  47. XCTAssertEqualObjects(user, newUser);
  48. XCTAssertTrue(GIDGoogleUser.supportsSecureCoding);
  49. }
  50. @end