Skip to content

Commit

Permalink
masking logic for APIKey
Browse files Browse the repository at this point in the history
  • Loading branch information
ski-u committed Dec 17, 2024
1 parent ba0ec5e commit 68a929e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
extension String {
import Models

extension APIKey {
var masked: String? {
guard let first else {
guard let first = rawValue.first else {
return nil
}
return "\(first)***"
Expand Down
2 changes: 1 addition & 1 deletion Features/Sources/Settings/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public struct SettingsView: View {

Spacer()

Text(store.apiKey.rawValue.masked ?? "None")
Text(store.apiKey.masked ?? "None")
.foregroundStyle(Color.secondary)
}
}
Expand Down
15 changes: 15 additions & 0 deletions Features/Tests/SettingsTests/APIKeyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Models
import Testing

@testable import Settings

struct APIKeyTests {
@Test
func masked() {
var key = APIKey(rawValue: "")
#expect(key.masked == nil)

key = .init(rawValue: "test")
#expect(key.masked == "t***")
}
}

0 comments on commit 68a929e

Please sign in to comment.