generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024.10-rc1 changes from main (#1086)
Co-authored-by: Federico Maccaroni <[email protected]> Co-authored-by: Pranish <[email protected]> Co-authored-by: aj-rosado <[email protected]> Co-authored-by: Phil Cappelli <[email protected]>
- Loading branch information
1 parent
23cb2a8
commit b06bd63
Showing
83 changed files
with
685 additions
and
192 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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -272,6 +272,7 @@ class AuthServiceTests: BitwardenTestCase { // swiftlint:disable:this type_body_ | |
// Verify the results. | ||
XCTAssertEqual(client.requests.count, 1) | ||
XCTAssertEqual(clientService.mockAuth.newAuthRequestEmail, "[email protected]") | ||
XCTAssertTrue(clientService.mockAuthIsPreAuth) | ||
XCTAssertEqual(result.authRequestResponse, authRequestResponse) | ||
XCTAssertEqual(result.requestId, LoginRequest.fixture().id) | ||
} | ||
|
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
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
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
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
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
47 changes: 47 additions & 0 deletions
47
BitwardenShared/Core/Platform/Utilities/DefaultFalse.swift
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,47 @@ | ||
/// A property wrapper that will default the wrapped value to `false` if decoding fails. This is | ||
/// useful for decoding a boolean value which may not be present in the response. | ||
/// | ||
@propertyWrapper | ||
struct DefaultFalse: Codable, Hashable { | ||
// MARK: Properties | ||
|
||
/// The wrapped value. | ||
let wrappedValue: Bool | ||
|
||
// MARK: Initialization | ||
|
||
/// Initialize a `DefaultFalse` with a wrapped value. | ||
/// | ||
/// - Parameter wrappedValue: The value that is contained in the property wrapper. | ||
/// | ||
init(wrappedValue: Bool) { | ||
self.wrappedValue = wrappedValue | ||
} | ||
|
||
// MARK: Decodable | ||
|
||
init(from decoder: any Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
wrappedValue = try container.decode(Bool.self) | ||
} | ||
|
||
// MARK: Encodable | ||
|
||
func encode(to encoder: Encoder) throws { | ||
try wrappedValue.encode(to: encoder) | ||
} | ||
} | ||
|
||
// MARK: - KeyedDecodingContainer | ||
|
||
extension KeyedDecodingContainer { | ||
/// When decoding a `DefaultFalse` wrapped value, if the property doesn't exist, default to `false`. | ||
/// | ||
/// - Parameters: | ||
/// - type: The type of value to attempt to decode. | ||
/// - key: The key used to decode the value. | ||
/// | ||
func decode(_ type: DefaultFalse.Type, forKey key: Key) throws -> DefaultFalse { | ||
try decodeIfPresent(type, forKey: key) ?? DefaultFalse(wrappedValue: false) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
BitwardenShared/Core/Platform/Utilities/DefaultFalseTests.swift
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,61 @@ | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
class DefaultFalseTests: BitwardenTestCase { | ||
// MARK: Types | ||
|
||
struct Model: Codable, Equatable { | ||
@DefaultFalse var value: Bool | ||
} | ||
|
||
// MARK: Tests | ||
|
||
/// `DefaultFalse` encodes a `false` wrapped value. | ||
func test_encode_false() throws { | ||
let subject = Model(value: false) | ||
let data = try JSONEncoder().encode(subject) | ||
XCTAssertEqual(String(data: data, encoding: .utf8), #"{"value":false}"#) | ||
} | ||
|
||
/// `DefaultFalse` encodes a `true` wrapped value. | ||
func test_encode_true() throws { | ||
let subject = Model(value: true) | ||
let data = try JSONEncoder().encode(subject) | ||
XCTAssertEqual(String(data: data, encoding: .utf8), #"{"value":true}"#) | ||
} | ||
|
||
/// Decoding a `DefaultFalse` wrapped value will decode a `false` value from the JSON. | ||
func test_decode_false() throws { | ||
let json = #"{"value": true}"# | ||
let data = try XCTUnwrap(json.data(using: .utf8)) | ||
let subject = try JSONDecoder().decode(Model.self, from: data) | ||
XCTAssertEqual(subject, Model(value: true)) | ||
} | ||
|
||
/// Decoding a `DefaultFalse` wrapped value will default the value to `false` if the key is | ||
/// missing from the JSON. | ||
func test_decode_missing() throws { | ||
let json = #"{}"# | ||
let data = try XCTUnwrap(json.data(using: .utf8)) | ||
let subject = try JSONDecoder().decode(Model.self, from: data) | ||
XCTAssertEqual(subject, Model(value: false)) | ||
} | ||
|
||
/// Decoding a `DefaultFalse` wrapped value will default the value to `false` if the value is | ||
/// `null` in the JSON. | ||
func test_decode_null() throws { | ||
let json = #"{"value": null}"# | ||
let data = try XCTUnwrap(json.data(using: .utf8)) | ||
let subject = try JSONDecoder().decode(Model.self, from: data) | ||
XCTAssertEqual(subject, Model(value: false)) | ||
} | ||
|
||
/// Decoding a `DefaultFalse` wrapped value will decode a `true` value from the JSON. | ||
func test_decode_true() throws { | ||
let json = #"{"value": true}"# | ||
let data = try XCTUnwrap(json.data(using: .utf8)) | ||
let subject = try JSONDecoder().decode(Model.self, from: data) | ||
XCTAssertEqual(subject, Model(value: true)) | ||
} | ||
} |
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
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
Oops, something went wrong.