-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'trunk' into issue/10259-dashboard-error-banner
- Loading branch information
Showing
30 changed files
with
654 additions
and
161 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
32 changes: 32 additions & 0 deletions
32
Networking/Networking/ApplicationPassword/AppicationPasswordEncoder.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,32 @@ | ||
import Foundation | ||
|
||
/// Utility class to encode the stored application password. | ||
/// By default it uses the stored application password. | ||
/// | ||
public struct ApplicationPasswordEncoder { | ||
|
||
/// Password envelope. | ||
/// | ||
private let passwordEnvelope: ApplicationPassword? | ||
|
||
public init(passwordEnvelope: ApplicationPassword? = nil) { | ||
self.passwordEnvelope = passwordEnvelope ?? ApplicationPasswordStorage().applicationPassword | ||
} | ||
|
||
/// Returns the application password on a base64 encoded format. | ||
/// The output is ready to be used in the authentication header. | ||
/// Returns `nil` if the password can't be encoded. | ||
/// | ||
public func encodedPassword() -> String? { | ||
guard let passwordEnvelope else { | ||
return nil | ||
} | ||
|
||
let loginString = "\(passwordEnvelope.wpOrgUsername):\(passwordEnvelope.password.secretValue)" | ||
guard let loginData = loginString.data(using: .utf8) else { | ||
return nil | ||
} | ||
|
||
return loginData.base64EncodedString() | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
Networking/NetworkingTests/ApplicationPassword/ApplicationPasswordEncoderTests.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,22 @@ | ||
import XCTest | ||
@testable import Networking | ||
|
||
final class ApplicationPasswordEncoderTests: XCTestCase { | ||
|
||
func test_nil_password_envelope_returns_nil_password() { | ||
let encoder = ApplicationPasswordEncoder(passwordEnvelope: nil) | ||
XCTAssertNil(encoder.encodedPassword()) | ||
} | ||
|
||
func test_sample_password_envelope_returns_encoded_password() { | ||
// Given | ||
let envelope = ApplicationPassword(wpOrgUsername: "This", password: .init("is-a-test"), uuid: "") | ||
|
||
// When | ||
let encoder = ApplicationPasswordEncoder(passwordEnvelope: envelope) | ||
|
||
// Then | ||
let expected = "VGhpczppcy1hLXRlc3Q=" /// `This:is-a-test` encoded with https://www.base64encode.org/ | ||
XCTAssertEqual(encoder.encodedPassword(), expected) | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
WooCommerce/Classes/ViewRelated/Coupons/CouponListView.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,20 @@ | ||
import SwiftUI | ||
import Yosemite | ||
|
||
struct CouponListView: UIViewControllerRepresentable { | ||
let siteID: Int64 | ||
let emptyStateActionTitle: String | ||
let emptyStateAction: (() -> Void) | ||
let onCouponSelected: ((Coupon) -> Void) | ||
|
||
func makeUIViewController(context: Self.Context) -> CouponListViewController { | ||
let viewController = CouponListViewController(siteID: siteID, | ||
showFeedbackBannerIfAppropriate: false, | ||
emptyStateActionTitle: emptyStateActionTitle, | ||
emptyStateAction: emptyStateAction, | ||
onCouponSelected: onCouponSelected) | ||
return viewController | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: CouponListViewController, context: Context) {} | ||
} |
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.