Skip to content

Add auto login for Debug #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@
ReferencedContainer = "container:Nextcloud.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "DEBUG_AUTO_LOGIN_PASSWORD"
value = "admin2"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "DEBUG_AUTO_LOGIN_BASE_URL"
value = "https://localhost:8444"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "DEBUG_AUTO_LOGIN_USERNAME"
value = "admin2"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<LocationScenarioReference
identifier = "London, England"
referenceType = "1">
Expand Down
49 changes: 49 additions & 0 deletions iOSClient/Login/NCLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
}

NCNetworking.shared.certificateDelegate = self

#if DEBUG
addDebugAutoLogInButton()
#endif
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -311,7 +315,7 @@

NextcloudKit.shared.getServerStatus(serverUrl: url) { [self] _, serverInfoResult in
switch serverInfoResult {
case .success(_):

Check warning on line 318 in iOSClient/Login/NCLogin.swift

View workflow job for this annotation

GitHub Actions / Lint

Empty Enum Arguments Violation: Arguments can be omitted when matching enums with associated values if they are not used (empty_enum_arguments)
if let host = URL(string: url)?.host {
NCNetworking.shared.writeCertificate(host: host)
}
Expand Down Expand Up @@ -489,3 +493,48 @@
loginButton.hideSpinnerAndShowButton()
}
}

#if DEBUG
extension NCLogin {
private func addDebugAutoLogInButton() {
let button = UIButton(type: .system)
button.setTitle("[DEBUG] Auto login", for: .normal)
button.backgroundColor = .black
button.setTitleColor(.white, for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
view.addSubview(button)

NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: qrCode.topAnchor, constant: -50),
button.widthAnchor.constraint(equalToConstant: 150),
button.heightAnchor.constraint(equalToConstant: 50)
])
}

private func autoLogIn(server: String, username: String, password: String) {
NextcloudKit.shared.getAppPassword(url: server, user: username, password: password) { [self] token, _, error in
guard let token, error == .success else {
present(UIAlertController.warning(message: error.error.localizedDescription), animated: true)
return
}

createAccount(urlBase: server, user: username, password: token)
}
}

@objc func buttonTapped() {
guard let baseUrl = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_BASE_URL"],
let username = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_USERNAME"],
let password = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_PASSWORD"] else {

let alert = UIAlertController.warning(title: "No env vars found for debug auto log in.", message: "Add DEBUG_AUTO_LOGIN_BASE_URL, DEBUG_AUTO_LOGIN_USERNAME and DEBUG_AUTO_LOGIN_PASSWORD to env vars")
present(alert, animated: true)
return
}

autoLogIn(server: baseUrl, username: username, password: password)
}
}
#endif
Loading