iOS/Sources/Shared/API/Fixtures/ServerFixture.swift
Bruno Pantaleão Gonçalves 094595a0bb
Move from local access security level to "Connection security level" (#3919)
<!-- Thank you for submitting a Pull Request and helping to improve Home
Assistant. Please complete the following sections to help the processing
and review of your changes. Please do not delete anything from this
template. -->

## Summary
<!-- Provide a brief summary of the changes you have made and most
importantly what they aim to achieve -->

## Screenshots
<!-- If this is a user-facing change not in the frontend, please include
screenshots in light and dark mode. -->

## Link to pull request in Documentation repository
<!-- Pull requests that add, change or remove functionality must have a
corresponding pull request in the Companion App Documentation repository
(https://github.com/home-assistant/companion.home-assistant). Please add
the number of this pull request after the "#" -->
Documentation: home-assistant/companion.home-assistant#

## Any other notes
<!-- If there is any other information of note, like if this Pull
Request is part of a bigger change, please include it here. -->
2025-10-28 13:45:52 +01:00

115 lines
3.7 KiB
Swift

import Foundation
public enum ServerFixture {
private static var standardInfo = ServerInfo(
name: "A Name",
connection: .init(
externalURL: nil,
internalURL: nil,
cloudhookURL: nil,
remoteUIURL: nil,
webhookID: "",
webhookSecret: nil,
internalSSIDs: nil,
internalHardwareAddresses: nil,
isLocalPushEnabled: false,
securityExceptions: .init(exceptions: []),
connectionAccessSecurityLevel: .undefined
),
token: .init(
accessToken: "",
refreshToken: "",
expiration: Date()
),
version: "123"
)
private static let originalStandardInfo = standardInfo
public static var standard: Server {
Server(identifier: "123", getter: {
standardInfo
}, setter: { newInfo in
standardInfo = newInfo
return true
})
}
/// Reset all fixtures to their original state - call this between tests
public static func reset() {
standardInfo = originalStandardInfo
remoteConnectionInfo = originalRemoteConnectionInfo
lessSecureAccessInfo = originalLessSecureAccessInfo
}
private static var remoteConnectionInfo = ServerInfo(
name: "Remote Server",
connection: .init(
externalURL: URL(string: "https://external.example.com"),
internalURL: URL(string: "http://internal.example.com"),
cloudhookURL: URL(string: "https://hooks.nabu.casa/webhook-id"),
remoteUIURL: URL(string: "https://ui.nabu.casa"),
webhookID: "webhook-id",
webhookSecret: "webhook-secret",
internalSSIDs: nil,
internalHardwareAddresses: nil,
isLocalPushEnabled: false,
securityExceptions: .init(exceptions: []),
connectionAccessSecurityLevel: .undefined
),
token: .init(
accessToken: "access-token",
refreshToken: "refresh-token",
expiration: Date()
),
version: "2023.12.0"
)
private static let originalRemoteConnectionInfo = remoteConnectionInfo
/// Server with remote connection setup for testing remote-compatible flows
public static var withRemoteConnection: Server {
Server(identifier: "remote", getter: {
remoteConnectionInfo
}, setter: { newInfo in
remoteConnectionInfo = newInfo
return true
})
}
private static var lessSecureAccessInfo = ServerInfo(
name: "Less Secure Server",
connection: .init(
externalURL: nil,
internalURL: URL(string: "http://internal.example.com"),
cloudhookURL: nil,
remoteUIURL: nil,
webhookID: "webhook-id",
webhookSecret: "webhook-secret",
internalSSIDs: nil,
internalHardwareAddresses: nil,
isLocalPushEnabled: false,
securityExceptions: .init(exceptions: []),
connectionAccessSecurityLevel: .lessSecure
),
token: .init(
accessToken: "access-token",
refreshToken: "refresh-token",
expiration: Date()
),
version: "2023.12.0"
)
private static let originalLessSecureAccessInfo = lessSecureAccessInfo
/// Server with less secure local access configured
public static var withLessSecureAccess: Server {
Server(identifier: "less-secure", getter: {
lessSecureAccessInfo
}, setter: { newInfo in
lessSecureAccessInfo = newInfo
return true
})
}
}