FIRAuthAppCredentialTests.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <XCTest/XCTest.h>
  17. #import "FirebaseAuth/Sources/SystemService/FIRAuthAppCredential.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @var kReceipt
  20. @brief The fake receipt value for testing.
  21. */
  22. static NSString *const kReceipt = @"RECEIPT";
  23. /** @var kSecret
  24. @brief The fake secret value for testing.
  25. */
  26. static NSString *const kSecret = @"SECRET";
  27. /** @class FIRAuthAppCredentialTests
  28. @brief Unit tests for @c FIRAuthAppCredential .
  29. */
  30. @interface FIRAuthAppCredentialTests : XCTestCase
  31. @end
  32. @implementation FIRAuthAppCredentialTests
  33. /** @fn testInitializer
  34. @brief Tests the initializer of the class.
  35. */
  36. - (void)testInitializer {
  37. FIRAuthAppCredential *credential = [[FIRAuthAppCredential alloc] initWithReceipt:kReceipt
  38. secret:kSecret];
  39. XCTAssertEqualObjects(credential.receipt, kReceipt);
  40. XCTAssertEqualObjects(credential.secret, kSecret);
  41. }
  42. /** @fn testSecureCoding
  43. @brief Tests the implementation of NSSecureCoding protocol.
  44. */
  45. - (void)testSecureCoding {
  46. XCTAssertTrue([FIRAuthAppCredential supportsSecureCoding]);
  47. FIRAuthAppCredential *credential = [[FIRAuthAppCredential alloc] initWithReceipt:kReceipt
  48. secret:kSecret];
  49. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:credential];
  50. XCTAssertNotNil(data);
  51. FIRAuthAppCredential *otherCredential = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  52. XCTAssertEqualObjects(otherCredential.receipt, kReceipt);
  53. XCTAssertEqualObjects(otherCredential.secret, kSecret);
  54. }
  55. @end
  56. NS_ASSUME_NONNULL_END