Skip to content
Snippets Groups Projects
Commit 9f48c2d4 authored by Thomas Evensen's avatar Thomas Evensen
Browse files

update

parent a5e5f727
No related branches found
No related tags found
No related merge requests found
//
// ArgumentsCreatSSHKeys.swift
// SSHCreateKey
//
// Created by Thomas Evensen on 15/08/2024.
//
import Foundation
struct ArgumentsCreatSSHKeys {
let keypathglobal = "/Users/thomas/.ssh_global"
let identityfileglobl = "global"
let userHomeDirectoryPathglobal = "/Users/thomas"
let sshkeypathandidentityfileglobal = "/Users/thomas/.ssh_global/global"
let argumentssshcopyidglobal = "/usr/bin/ssh-copy-id -i ~/.ssh_global/global -p 2222 thomas@raspberrypi"
let keypathdefault = "/Users/thomas/.ssh"
let identityfiledefault = "id_rsa"
let userHomeDirectoryPathdefault = "/Users/thomas"
let sshkeypathandidentityfiledefault = "/Users/thomas/.ssh/id_rsa"
let argumentssshcopyiddefault = "/usr/bin/ssh-copy-id -i /Users/thomas/.ssh/id_rsa thomas@raspberrypi"
/*
/Users/thomas/.ssh
id_rsa
/Users/thomas
/Users/thomas/.ssh/id_rsa
/usr/bin/ssh-copy-id -i /Users/thomas/.ssh/id_rsa thomas@raspberrypi
*/
/*
let arg3 = await sshcreatekey.keypathonly
print(arg3 ?? "")
let arg4 = await sshcreatekey.identityfile
print(arg4 ?? "")
let arg5 = await sshcreatekey.userHomeDirectoryPath
print(arg5 ?? "")
let arg6 = await sshcreatekey.sshkeypathandidentityfile
print(arg6 ?? "")
let arg7 = await sshcreatekey.argumentssshcopyid(offsiteServer: "raspberrypi", offsiteUsername: "thomas")
pri
*/
}
......@@ -8,107 +8,70 @@ import Testing
let loadtestdata = ReadTestdataFromGitHub()
await loadtestdata.getdata()
testconfigurations = loadtestdata.testconfigurations
if let testconfigurations {
let sshcreatekey = await SSHCreateKey(sharedsshport: String(TestSharedReference.shared.sshport ?? -1),
sharedsshkeypathandidentityfile: TestSharedReference.shared.sshkeypathandidentityfile)
let arg3 = await sshcreatekey.keypathonly
print(arg3 ?? "")
let arg4 = await sshcreatekey.identityfile
print(arg4 ?? "")
let arg5 = await sshcreatekey.userHomeDirectoryPath
print(arg5 ?? "")
let arg6 = await sshcreatekey.sshkeypathandidentityfile
print(arg6 ?? "")
let arg7 = await sshcreatekey.argumentssshcopyid(offsiteServer: "raspberrypi", offsiteUsername: "thomas")
print(arg7)
}
let sshcreatekey = await SSHCreateKey(sharedsshport: String(TestSharedReference.shared.sshport ?? -1),
sharedsshkeypathandidentityfile: TestSharedReference.shared.sshkeypathandidentityfile)
let arg3 = await sshcreatekey.keypathonly
#expect(ArgumentsCreatSSHKeys().keypathglobal == arg3)
let arg4 = await sshcreatekey.identityfile
#expect(ArgumentsCreatSSHKeys().identityfileglobl == arg4)
let arg5 = await sshcreatekey.userHomeDirectoryPath
#expect(ArgumentsCreatSSHKeys().userHomeDirectoryPathglobal == arg5)
let arg6 = await sshcreatekey.sshkeypathandidentityfile
#expect(ArgumentsCreatSSHKeys().sshkeypathandidentityfileglobal == arg6)
let arg7 = await sshcreatekey.argumentssshcopyid(offsiteServer: "raspberrypi", offsiteUsername: "thomas")
#expect(ArgumentsCreatSSHKeys().argumentssshcopyidglobal == arg7)
}
@Test func LodaDataCreateSSHKeysdefault() async {
let loadtestdata = ReadTestdataFromGitHub()
await loadtestdata.getdata()
testconfigurations = loadtestdata.testconfigurations
if let testconfigurations {
let port = -1
let identityfile: String? = nil
let sshcreatekey = await SSHCreateKey(sharedsshport: String(port),
sharedsshkeypathandidentityfile: identityfile)
let arg3 = await sshcreatekey.keypathonly
print(arg3 ?? "")
let arg4 = await sshcreatekey.identityfile
print(arg4 ?? "")
let arg5 = await sshcreatekey.userHomeDirectoryPath
print(arg5 ?? "")
let arg6 = await sshcreatekey.sshkeypathandidentityfile
print(arg6 ?? "")
let arg7 = await sshcreatekey.argumentssshcopyid(offsiteServer: "raspberrypi", offsiteUsername: "thomas")
print(arg7)
}
// Sett Shareddata to nil oe default values
let port = -1
let identityfile: String? = nil
let sshcreatekey = await SSHCreateKey(sharedsshport: String(port),
sharedsshkeypathandidentityfile: identityfile)
let arg3 = await sshcreatekey.keypathonly
#expect(ArgumentsCreatSSHKeys().keypathdefault == arg3)
let arg4 = await sshcreatekey.identityfile
#expect(ArgumentsCreatSSHKeys().identityfiledefault == arg4)
let arg5 = await sshcreatekey.userHomeDirectoryPath
#expect(ArgumentsCreatSSHKeys().userHomeDirectoryPathdefault == arg5)
let arg6 = await sshcreatekey.sshkeypathandidentityfile
#expect(ArgumentsCreatSSHKeys().sshkeypathandidentityfiledefault == arg6)
let arg7 = await sshcreatekey.argumentssshcopyid(offsiteServer: "raspberrypi", offsiteUsername: "thomas")
#expect(ArgumentsCreatSSHKeys().argumentssshcopyiddefault == arg7)
}
@Test func createkeys() async {
let loadtestdata = ReadTestdataFromGitHub()
await loadtestdata.getdata()
testconfigurations = loadtestdata.testconfigurations
if let testconfigurations {
do {
let sshcreatekey = await SSHCreateKey(sharedsshport: String(TestSharedReference.shared.sshport ?? -1),
sharedsshkeypathandidentityfile: TestSharedReference.shared.sshkeypathandidentityfile)
let present = try await sshcreatekey.islocalpublicrsakeypresent()
if present == false {
// If new keypath is set create it
let sshrootpath = await sshcreatekey.testcreatesshkeyrootpath()
// Create keys
let arguments = await sshcreatekey.argumentscreatekey()
let command = "/usr/bin/ssh-keygen"
print(sshrootpath ?? "")
print(command)
print(arguments?.joined(separator: " ") ?? "")
}
} catch let e {
let error = e
print(error)
}
}
}
@Test func createkeysdefault() async {
let loadtestdata = ReadTestdataFromGitHub()
await loadtestdata.getdata()
testconfigurations = loadtestdata.testconfigurations
if let testconfigurations {
do {
let port = -1
let identityfile: String? = nil
let sshcreatekey = await SSHCreateKey(sharedsshport: String(port),
sharedsshkeypathandidentityfile: identityfile)
let present = try await sshcreatekey.islocalpublicrsakeypresent()
if present == false {
// If new keypath is set create it
let sshrootpath = await sshcreatekey.testcreatesshkeyrootpath()
// Create keys
let arguments = await sshcreatekey.argumentscreatekey()
let command = "/usr/bin/ssh-keygen"
print(sshrootpath ?? "")
print(command)
print(arguments?.joined(separator: " ") ?? "")
}
} catch let e {
let error = e
print(error)
}
}
let sshcreatekey = await SSHCreateKey(sharedsshport: String(TestSharedReference.shared.sshport ?? -1),
sharedsshkeypathandidentityfile: TestSharedReference.shared.sshkeypathandidentityfile)
// If new keypath is set create it
let sshrootpath = await sshcreatekey.testcreatesshkeyrootpath()
// Create keys
let arguments = await sshcreatekey.argumentscreatekey()
print(sshrootpath ?? "")
print(arguments ?? "")
}
}
@Test func createkeysdefault() async {
let port = -1
let identityfile: String? = nil
let sshcreatekey = await SSHCreateKey(sharedsshport: String(port),
sharedsshkeypathandidentityfile: identityfile)
let sshrootpath = await sshcreatekey.testcreatesshkeyrootpath()
// Create keys
let arguments = await sshcreatekey.argumentscreatekey()
print(sshrootpath ?? "")
print(arguments ?? "")
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment