fix dependencies building, looks like i cant use the sim bc libs are compiled for ios

This commit is contained in:
neon443
2025-06-05 11:17:37 +01:00
parent 2a2ed76f58
commit 7d206478ea
92 changed files with 14342 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
#import <XCTest/XCTest.h>
#import "NMSFTPFile.h"
@interface NMSFTPFileTests : XCTestCase
@end
@implementation NMSFTPFileTests {
NMSFTPFile *_file;
}
- (void)setUp {
[super setUp];
_file = [[NMSFTPFile alloc] initWithFilename:@"test.txt"];
}
/**
Tests whether the filename attribute is correct after initialization.
*/
- (void)testInitialization {
XCTAssertEqualObjects(_file.filename, @"test.txt", @"Filename attribut has not been set");
NMSFTPFile *anotherFile = [NMSFTPFile fileWithName:@"test.txt"];
XCTAssertEqualObjects(anotherFile.filename, @"test.txt", @"Filename attribut has not been set");
}
/**
Tests whether the permissions conversion from numeric to symbolic notation is correct
*/
-(void)testPermissionsConversion {
LIBSSH2_SFTP_ATTRIBUTES attributes;
attributes.permissions = 33188;
[_file populateValuesFromSFTPAttributes:attributes];
XCTAssertEqualObjects(_file.permissions, @"-rw-r--r--", @"The symbolic permissions notation is not correct.");
}
@end

View File

@@ -0,0 +1,4 @@
#import <XCTest/XCTest.h>
@interface NMSFTPTests : XCTestCase
@end

View File

@@ -0,0 +1,207 @@
#import "NMSFTPTests.h"
#import "ConfigHelper.h"
#import <NMSSH/NMSSH.h>
@interface NMSFTPTests () {
NSDictionary *settings;
NMSSHSession *session;
NMSFTP *sftp;
}
@end
@implementation NMSFTPTests
// -----------------------------------------------------------------------------
// TEST SETUP
// -----------------------------------------------------------------------------
- (void)setUp {
settings = [ConfigHelper valueForKey:@"valid_password_protected_server"];
session = [NMSSHSession connectToHost:[settings objectForKey:@"host"]
withUsername:[settings objectForKey:@"user"]];
[session authenticateByPassword:[settings objectForKey:@"password"]];
assert([session isAuthorized]);
sftp = [NMSFTP connectWithSession:session];
}
- (void)tearDown {
if (sftp) {
[sftp disconnect];
sftp = nil;
}
if (session) {
[session disconnect];
session = nil;
}
}
// -----------------------------------------------------------------------------
// CONNECTION TESTS
// -----------------------------------------------------------------------------
- (void)testConnectWithValidSession {
XCTAssertTrue([sftp isConnected], @"Test that connection worked");
}
// -----------------------------------------------------------------------------
// TEST MANIPULATING DIRECTORIES
// -----------------------------------------------------------------------------
- (void)testCreateMoveAndDeleteDirectoryAtWritablePathWorks {
NSString *path = [NSString stringWithFormat:@"%@mkdir_test",
[settings objectForKey:@"writable_dir"]];
NSString *destPath = [NSString stringWithFormat:@"%@mvdir_test",
[settings objectForKey:@"writable_dir"]];
XCTAssertTrue([sftp createDirectoryAtPath:path],
@"Try to create directory at valid path");
XCTAssertTrue([sftp directoryExistsAtPath:path],
@"Directory exists at path");
XCTAssertTrue([sftp moveItemAtPath:path toPath:destPath],
@"Try to move a directory");
XCTAssertTrue([sftp removeDirectoryAtPath:destPath],
@"Try to remove directory");
}
- (void)testCreateDirectoryAtNonWritablePathFails {
NSString *path = [NSString stringWithFormat:@"%@mkdir_test",
[settings objectForKey:@"non_writable_dir"]];
XCTAssertFalse([sftp createDirectoryAtPath:path],
@"Try to create directory at invalid path");
}
- (void)testListingContentsOfDirectory {
NSString *baseDir = [NSString stringWithFormat:@"%@listing/",
[settings objectForKey:@"writable_dir"]];
NSArray *dirs = @[@"a", @"b", @"c"];
NSArray *files = @[@"d.txt", @"e.txt", @"f.txt"];
// Setup basedir
[sftp createDirectoryAtPath:baseDir];
// Setup subdirs
for (NSString *dir in dirs) {
[sftp createDirectoryAtPath:[baseDir stringByAppendingString:dir]];
}
// Setup files
NSData *contents = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
for (NSString *file in files) {
[sftp writeContents:contents
toFileAtPath:[baseDir stringByAppendingString:file]];
}
// Test entry listing
NSArray *entries = @[[NMSFTPFile fileWithName:@"a/"],
[NMSFTPFile fileWithName:@"b/"],
[NMSFTPFile fileWithName:@"c/"],
[NMSFTPFile fileWithName:@"d.txt"],
[NMSFTPFile fileWithName:@"e.txt"],
[NMSFTPFile fileWithName:@"f.txt"]];
XCTAssertEqualObjects([sftp contentsOfDirectoryAtPath:baseDir], entries,
@"Get a list of directory entries");
// Cleanup subdirs
for (NSString *dir in dirs) {
[sftp removeDirectoryAtPath:[baseDir stringByAppendingString:dir]];
}
// Cleanup files
for (NSString *file in files) {
[sftp removeFileAtPath:[baseDir stringByAppendingString:file]];
}
// Cleanup basedir
[sftp removeDirectoryAtPath:baseDir];
}
// -----------------------------------------------------------------------------
// TEST MANIPULATING FILES AND SYMLINKS
// -----------------------------------------------------------------------------
- (void)testCreateAndDeleteSymlinkAtWritablePath {
// Set up a new directory to symlink to
NSString *path = [NSString stringWithFormat:@"%@mkdir_test",
[settings objectForKey:@"writable_dir"]];
[sftp createDirectoryAtPath:path];
// Create symlink
NSString *linkPath = [NSString stringWithFormat:@"%@symlink_test",
[settings objectForKey:@"writable_dir"]];
XCTAssertTrue([sftp createSymbolicLinkAtPath:linkPath
withDestinationPath:path], @"Create symbolic link");
// Remove symlink
XCTAssertTrue([sftp removeFileAtPath:linkPath], @"Remove symlink");
// Cleanup
[sftp removeDirectoryAtPath:path];
}
- (void)testCreateMoveAndDeleteFileAtWriteablePath {
NSString *path = [NSString stringWithFormat:@"%@file_test.txt",
[settings objectForKey:@"writable_dir"]];
NSString *destPath = [NSString stringWithFormat:@"%@mvfile_test.txt",
[settings objectForKey:@"writable_dir"]];
NSMutableData *contents = [[@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]
mutableCopy];
XCTAssertTrue([sftp writeContents:contents toFileAtPath:path],
@"Write contents to file");
XCTAssertEqualObjects([sftp contentsAtPath:path], contents,
@"Read contents at path");
NSData *moreContents = [@"\nBye!" dataUsingEncoding:NSUTF8StringEncoding];
XCTAssertTrue([sftp appendContents:moreContents toFileAtPath:path],
@"Append contents to the end of a file");
[contents appendData:moreContents];
XCTAssertEqualObjects([sftp contentsAtPath:path], contents,
@"Read appended contents at path");
XCTAssertTrue([sftp moveItemAtPath:path toPath:destPath], @"Move a file");
XCTAssertTrue([sftp fileExistsAtPath:destPath], @"File exists at path");
XCTAssertFalse([sftp fileExistsAtPath:[settings objectForKey:@"writable_dir"]],
@"Should return false if a directory is provided");
XCTAssertTrue([sftp removeFileAtPath:destPath], @"Remove file");
}
-(void)testRetrievingFileInfo {
NSString *destPath = [[settings objectForKey:@"writable_dir"] stringByAppendingPathComponent: @"file_test.txt"];
NSString *destDirectoryPath = [[settings objectForKey:@"writable_dir"] stringByAppendingPathComponent: @"directory_test"];
XCTAssertTrue([sftp writeContents:[@"test" dataUsingEncoding:NSUTF8StringEncoding] toFileAtPath:destPath],@"Write contents to file");
XCTAssertTrue([sftp createDirectoryAtPath:destDirectoryPath], @"Couldn't create directory");
NMSFTPFile *fileInfo = [sftp infoForFileAtPath:destPath];
XCTAssertNotNil(fileInfo, @"Couldn't retrieve file info");
XCTAssertNotNil(fileInfo.filename, @"Couldn't retrieve filename");
XCTAssertNotNil(fileInfo.fileSize, @"Couldn't retrieve file size");
XCTAssertNotNil(fileInfo.permissions, @"Couldn't retrieve permissions");
XCTAssertNotNil(fileInfo.modificationDate, @"Couldn't retrieve modification date");
XCTAssertTrue(fileInfo.ownerGroupID > 0, @"Couldn't retrieve owner group ID");
XCTAssertTrue(fileInfo.ownerUserID > 0, @"Couldn't retrieve owner user ID");
XCTAssertFalse(fileInfo.isDirectory, @"File isn't a driectory");
NMSFTPFile *directoryInfo = [sftp infoForFileAtPath:destDirectoryPath];
XCTAssertTrue(directoryInfo.isDirectory, @"Target file is a directory");
XCTAssertTrue([sftp removeFileAtPath:destPath], @"Remove file");
XCTAssertTrue([sftp removeDirectoryAtPath:destDirectoryPath], @"Remove directory");
}
@end

View File

@@ -0,0 +1,4 @@
#import <XCTest/XCTest.h>
@interface NMSSHChannelTests : XCTestCase
@end

View File

@@ -0,0 +1,135 @@
#import "NMSSHChannelTests.h"
#import "ConfigHelper.h"
#import <NMSSH/NMSSH.h>
@interface NMSSHChannelTests () {
NSDictionary *settings;
NSString *localFilePath;
NMSSHChannel *channel;
NMSSHSession *session;
}
@end
@implementation NMSSHChannelTests
// -----------------------------------------------------------------------------
// TEST SETUP
// -----------------------------------------------------------------------------
- (void)setUp {
settings = [ConfigHelper valueForKey:@"valid_password_protected_server"];
session = [NMSSHSession connectToHost:[settings objectForKey:@"host"]
withUsername:[settings objectForKey:@"user"]];
[session authenticateByPassword:[settings objectForKey:@"password"]];
assert([session isAuthorized]);
// Setup test file for SCP
localFilePath = [@"~/nmssh-test.txt" stringByExpandingTildeInPath];
NSData *contents = [@"hello" dataUsingEncoding:NSUTF8StringEncoding];
[[NSFileManager defaultManager] createFileAtPath:localFilePath
contents:contents
attributes:nil];
}
- (void)tearDown {
if (channel) {
channel = nil;
}
if (session) {
[session disconnect];
session = nil;
}
// Cleanup SCP test files
if ([[NSFileManager defaultManager] fileExistsAtPath:localFilePath]) {
[[NSFileManager defaultManager] removeItemAtPath:localFilePath
error:nil];
}
}
// -----------------------------------------------------------------------------
// SHELL EXECUTION TESTS
// -----------------------------------------------------------------------------
- (void)testCreatingChannelWorks {
XCTAssertNoThrow(channel = [[NMSSHChannel alloc] initWithSession:session],
@"Setting up channel does not throw exception");
}
- (void)testExecutingShellCommand {
channel = [[NMSSHChannel alloc] initWithSession:session];
NSError *error = nil;
XCTAssertNoThrow([channel execute:[settings objectForKey:@"execute_command"]
error:&error],
@"Execution should not throw an exception");
XCTAssertEqualObjects([channel lastResponse],
[settings objectForKey:@"execute_expected_response"],
@"Execution returns the expected response");
}
// -----------------------------------------------------------------------------
// SCP FILE TRANSFER TESTS
// -----------------------------------------------------------------------------
- (void)testUploadingFileToWritableDirWorks {
channel = [[NMSSHChannel alloc] initWithSession:session];
NSString *dir = [settings objectForKey:@"writable_dir"];
XCTAssertTrue([dir hasSuffix:@"/"], @"Directory must end with a slash");
BOOL result;
XCTAssertNoThrow(result = [channel uploadFile:localFilePath to:dir],
@"Uploading file to writable dir doesn't throw exception");
XCTAssertTrue(result, @"Uploading to writable dir should work.");
}
- (void)testUploadingFileToNonWritableDirFails {
channel = [[NMSSHChannel alloc] initWithSession:session];
NSString *dir = [settings objectForKey:@"non_writable_dir"];
BOOL result;
XCTAssertNoThrow(result = [channel uploadFile:localFilePath to:dir],
@"Uploading file to non-writable dir doesn't throw"
@"exception");
XCTAssertFalse(result, @"Uploading to non-writable dir should not work.");
}
- (void)testDownloadingExistingFileWorks {
channel = [[NMSSHChannel alloc] initWithSession:session];
[[NSFileManager defaultManager] removeItemAtPath:localFilePath error:nil];
NSString *remoteFile = [[settings objectForKey:@"writable_dir"] stringByAppendingPathComponent:@"nmssh-test.txt"];
BOOL result;
XCTAssertNoThrow(result = [channel downloadFile:remoteFile to:localFilePath],
@"Downloading existing file doesn't throw exception");
XCTAssertTrue(result, @"Downloading existing file should work.");
XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:localFilePath],
@"A file has been created");
}
- (void)testDownloadingNonExistingFileFails {
channel = [[NMSSHChannel alloc] initWithSession:session];
[[NSFileManager defaultManager] removeItemAtPath:localFilePath error:nil];
NSString *remoteFile = [NSString stringWithFormat:@"%@nmssh-test.txt",
[settings objectForKey:@"non_writable_dir"]];
BOOL result;
XCTAssertNoThrow(result = [channel downloadFile:remoteFile to:localFilePath],
@"Downloading non-existing file doesn't throw exception");
XCTAssertFalse(result, @"Downloading non-existing file should not work.");
XCTAssertFalse([[NSFileManager defaultManager] fileExistsAtPath:localFilePath],
@"A file has not been created");
}
@end

View File

@@ -0,0 +1,612 @@
//
// NMSSHConfigTests.m
// NMSSH
//
// Created by George Nachman on 5/8/14.
//
//
#import <XCTest/XCTest.h>
#import "NMSSHConfig.h"
#import "NMSSHHostConfig.h"
@interface NMSSHConfigTests : XCTestCase
@end
@implementation NMSSHConfigTests
/**
Tests that an empty config file is ok
*/
- (void)testEmptyConfig {
NSString *contents = @"";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 0, @"Wrong number of configs read");
}
/**
Tests that a config file with all supported keywords is properly read.
*/
- (void)testAllKeywords {
NSString *contents =
@"Host pattern\n"
@" Hostname hostname\n"
@" User user\n"
@" Port 1234\n"
@" IdentityFile id_file\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.user, @"user", @"Users don't match");
XCTAssertEqualObjects(hostConfig.port, @1234, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file" ], @"Identity files don't match");
}
/**
Tests that comments are ignored.
*/
- (void)testCommentsIgnored {
NSString *contents =
@"# Comment\n"
@"Host pattern\n"
@"# Comment\n"
@" Hostname hostname\n"
@"# Comment\n"
@" Port 1234\n"
@"# Comment\n"
@" IdentityFile id_file\n"
@"# Comment\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @1234, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file" ], @"Identity files don't match");
}
/**
Tests that empty lines are ignored.
*/
- (void)testEmptyLinesIgnored {
NSString *contents =
@"\n"
@"Host pattern\n"
@"\n"
@" Hostname hostname\n"
@"\n"
@" Port 1234\n"
@"\n"
@" IdentityFile id_file\n"
@"\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @1234, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file" ], @"Identity files don't match");
}
/**
Tests that unknown keywords are ignored.
*/
- (void)testIgnoreUnknownKeywords {
NSString *contents =
@"Host pattern\n"
@" Hostname hostname\n"
@" Port 1234\n"
@" jfkldsajfdkl fjdkslafjdl fdjkla fjdslkf asdl\n"
@" IdentityFile id_file\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @1234, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file" ], @"Identity files don't match");
}
/**
Tests that a malformed port line doesn't break parsing
*/
- (void)testMalformedPort {
NSString *contents =
@"Host pattern\n"
@" Hostname hostname\n"
@" Port\n"
@" IdentityFile id_file\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
XCTAssertNil(hostConfig.port, @"Port should be nil");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file" ], @"Identity files don't match");
}
/**
Tests that multiple patterns are parsed properly
*/
- (void)testMultiplePatterns {
NSString *contents =
@"Host pattern1 pattern2\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
NSArray *expected = @[ @"pattern1", @"pattern2" ];
XCTAssertEqualObjects(hostConfig.hostPatterns, expected, @"Patterns don't match");
}
/**
Tests that quoted patterns are parsed properly
*/
- (void)testQuotedPatterns {
NSString *contents =
@"Host pattern1 \"a quoted pattern\" pattern2 \"foo bar\" \"baz\"\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
NSArray *expected = @[ @"pattern1", @"a quoted pattern", @"pattern2", @"foo bar", @"baz" ];
XCTAssertEqualObjects(hostConfig.hostPatterns, expected, @"Patterns don't match");
}
/**
Tests that an unterminated quoted patterns are ignored.
*/
- (void)testUnterminatedQuotation {
NSString *contents =
@"Host pattern1 \"unterminated quotation\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
NSArray *expected = @[ @"pattern1" ];
XCTAssertEqualObjects(hostConfig.hostPatterns, expected, @"Patterns don't match");
}
/**
Tests that multiple identity file commands are respected.
*/
- (void)testMultipleIdentityFile {
NSString *contents =
@"Host pattern\n"
@" Hostname hostname\n"
@" Port 1234\n"
@" IdentityFile id_file1\n"
@" IdentityFile id_file2\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
NSArray *expected = @[ @"id_file1", @"id_file2" ];
XCTAssertEqualObjects(hostConfig.identityFiles, expected, @"Identity files don't match");
}
/**
Tests that trailing and midline spaces are ignored
*/
- (void)testExtraSpaces {
NSString *contents =
@" Host pattern \"quoted pattern\" \" \" \n"
@" Hostname hostname \n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 1, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
NSArray *expected = @[ @"pattern", @"quoted pattern", @" " ];
XCTAssertEqualObjects(hostConfig.hostPatterns, expected, @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname", @"Hostnames don't match");
}
/**
Tests multiple hosts
*/
- (void)testMultipleHosts {
NSString *contents =
@"Host pattern1\n"
@" Hostname hostname1\n"
@" Port 1\n"
@" IdentityFile id_file1\n"
@"Host pattern2\n"
@" Hostname hostname2\n"
@" Port 2\n"
@" IdentityFile id_file2\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NSArray *hostConfigs = config.hostConfigs;
XCTAssertEqual([hostConfigs count], 2, @"Wrong number of configs read");
NMSSHHostConfig *hostConfig = hostConfigs[0];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern1" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @1, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file1" ],
@"Identity files don't match");
hostConfig = hostConfigs[1];
XCTAssertEqualObjects(hostConfig.hostPatterns, @[ @"pattern2" ], @"Patterns don't match");
XCTAssertEqualObjects(hostConfig.hostname, @"hostname2", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @2, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.identityFiles, @[ @"id_file2" ],
@"Identity files don't match");
}
// -----------------------------------------------------------------------------
#pragma mark - TEST MATCHING
// -----------------------------------------------------------------------------
/**
Test matching a simple pattern
*/
- (void)testSimplestPossiblePattern {
NSString *contents =
@"Host pattern1\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
}
/**
Test that a simple pattern fails when it ought to.
*/
- (void)testSimplestPossiblePatternNoMatch {
NSString *contents =
@"Host pattern1\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a pattern list of simple patterns works.
*/
- (void)testSimplePatternList {
NSString *contents =
@"Host pattern1,pattern2\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern3"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a question mark wildcard works
*/
- (void)testSingleCharWildcard {
NSString *contents =
@"Host pattern?\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"Xattern3"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a lone star matches everything
*/
- (void)testLoneStarMatchesAll {
NSString *contents =
@"Host *\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@""];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
}
/**
Test that a star suffix matches all suffixes
*/
- (void)testStarSuffix {
NSString *contents =
@"Host a*\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"abcdef"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"a"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@""];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a midline star works
*/
- (void)testMidlineStar {
NSString *contents =
@"Host abc*xyz\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"abcxyz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abc123xyz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abc"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"xyz"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"abxyz"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"abcyz"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"abcabc"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a star prefix works
*/
- (void)testLeadingStar {
NSString *contents =
@"Host *xyz\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"xyz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"123xyz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"xyz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abc"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@""];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that multiple disjoint stars work.
*/
- (void)testMultipleDisjointStars {
NSString *contents =
@"Host a*b*c\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"a12b34c"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abc"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abc1"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@""];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that two stars in a row work
*/
- (void)testConsecutiveStars {
NSString *contents =
@"Host a**z\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"abcz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"az"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"a"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@""];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test that a star followed by a question mark works
*/
- (void)testStarQuestionMark {
NSString *contents =
@"Host a*?z\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"abcz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"abz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"az"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"a"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@""];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test a host with multiple pattern lists
*/
- (void)testMultiplePatternLists {
NSString *contents =
@"Host pattern1,pattern2 pattern3,pattern4\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern3"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"pattern4"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
}
/**
Test negation alone
*/
- (void)testNegationAlone {
NSString *contents =
@"Host !pattern1\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"pattern1"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"pattern2"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test negation in combination with a matchable pattern
*/
- (void)testNegationPlusMatchablePattern {
NSString *contents =
@"Host !*x* a*\n"
@" Hostname hostname1\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"axy"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"abc"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"b"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test two rules where the first negates and the second matches.
*/
- (void)testTwoRulesWhereFirstNegatesAndSecondMatches {
NSString *contents =
@"Host !*x* a*\n"
@" Hostname hostname1\n"
@"Host *z\n"
@" Hostname hostname2\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"axy"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
hostConfig = [config hostConfigForHost:@"abc"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Match failed");
hostConfig = [config hostConfigForHost:@"axz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname2", @"Match failed");
hostConfig = [config hostConfigForHost:@"xz"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname2", @"Match failed");
hostConfig = [config hostConfigForHost:@"z"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname2", @"Match failed");
hostConfig = [config hostConfigForHost:@"b"];
XCTAssertNil(hostConfig, @"Match should have failed but didn't");
}
/**
Test two rules that both match. They should be merged.
*/
- (void)testMergeTwoMatchingRules {
NSString *contents =
@"Host *\n"
@" Hostname hostname1\n"
@" Port 1\n"
@" IdentityFile id_file1\n"
@"Host *\n"
@" Hostname hostname2\n"
@" Port 2\n"
@" User user\n"
@" IdentityFile id_file2\n";
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:contents];
NMSSHHostConfig *hostConfig = [config hostConfigForHost:@"hostname"];
XCTAssertEqualObjects(hostConfig.hostname, @"hostname1", @"Hostnames don't match");
XCTAssertEqualObjects(hostConfig.port, @1, @"Port doesn't match");
XCTAssertEqualObjects(hostConfig.user, @"user", @"Users doesn't match");
NSArray *expected = @[ @"id_file1", @"id_file2" ];
XCTAssertEqualObjects(hostConfig.identityFiles, expected,
@"Identity files don't match");
}
@end

View File

@@ -0,0 +1,4 @@
#import <XCTest/XCTest.h>
@interface NMSSHSessionTests : XCTestCase
@end

View File

@@ -0,0 +1,334 @@
#import "NMSSHSessionTests.h"
#import "NMSSHConfig.h"
#import "NMSSHHostConfig.h"
#import "ConfigHelper.h"
#import <NMSSH/NMSSH.h>
@interface NMSSHSessionTests () {
NSDictionary *validPasswordProtectedServer;
NSDictionary *validPublicKeyProtectedServer;
NSDictionary *validAgentServer;
NSDictionary *invalidServer;
NMSSHSession *session;
}
@end
@implementation NMSSHSessionTests
// -----------------------------------------------------------------------------
// TEST SETUP
// -----------------------------------------------------------------------------
- (void)setUp {
validPasswordProtectedServer = [ConfigHelper valueForKey:
@"valid_password_protected_server"];
validPublicKeyProtectedServer = [ConfigHelper valueForKey:
@"valid_public_key_protected_server"];
invalidServer = [ConfigHelper valueForKey:@"invalid_server"];
validAgentServer = [ConfigHelper valueForKey:@"valid_agent_server"];
}
- (void)tearDown {
if (session) {
[session disconnect];
session = nil;
}
}
// -----------------------------------------------------------------------------
// CONNECTION TESTS
// -----------------------------------------------------------------------------
- (void)testConnectionToValidServerWorks {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [validPasswordProtectedServer
objectForKey:@"user"];
XCTAssertNoThrow(session = [NMSSHSession connectToHost:host
withUsername:username],
@"Connecting to a valid server does not throw exception");
XCTAssertTrue([session isConnected],
@"Connection to valid server should work");
}
- (void)testConnectionToInvalidServerFails {
NSString *host = [invalidServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];
XCTAssertNoThrow(session = [NMSSHSession connectToHost:host
withUsername:username],
@"Connecting to a invalid server does not throw exception");
XCTAssertFalse([session isConnected],
@"Connection to invalid server should not work");
}
// -----------------------------------------------------------------------------
// AUTHENTICATION TESTS
// -----------------------------------------------------------------------------
- (void)testPasswordAuthenticationWithValidPasswordWorks {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [validPasswordProtectedServer
objectForKey:@"user"];
NSString *password = [validPasswordProtectedServer
objectForKey:@"password"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPassword:password],
@"Authentication with valid password doesn't throw"
@"exception");
XCTAssertTrue([session isAuthorized],
@"Authentication with valid password should work");
}
- (void)testPasswordAuthenticationWithInvalidPasswordFails {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [validPasswordProtectedServer
objectForKey:@"user"];
NSString *password = [invalidServer objectForKey:@"password"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPassword:password],
@"Authentication with invalid password doesn't throw"
@"exception");
XCTAssertFalse([session isAuthorized],
@"Authentication with invalid password should not work");
}
- (void)testPasswordAuthenticationWithInvalidUserFails {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];
NSString *password = [invalidServer objectForKey:@"password"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPassword:password],
@"Authentication with invalid username/password doesn't"
@"throw exception");
XCTAssertFalse([session isAuthorized],
@"Authentication with invalid username/password should not"
@"work");
}
- (void)testPublicKeyAuthenticationWithValidKeyWorks {
NSString *host = [validPublicKeyProtectedServer objectForKey:@"host"];
NSString *username = [validPublicKeyProtectedServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"valid_public_key"];
NSString *password = [validPublicKeyProtectedServer
objectForKey:@"password"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPublicKey:publicKey
privateKey:[publicKey stringByDeletingPathExtension]
andPassword:password],
@"Authentication with valid public key doesn't throw"
@"exception");
XCTAssertTrue([session isAuthorized],
@"Authentication with valid public key should work");
}
- (void)testPublicKeyAuthenticationWithInvalidPasswordFails {
NSString *host = [validPublicKeyProtectedServer objectForKey:@"host"];
NSString *username = [validPublicKeyProtectedServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"valid_public_key"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPublicKey:publicKey
privateKey:[publicKey stringByDeletingPathExtension]
andPassword:nil],
@"Public key authentication with invalid password doesn't"
@"throw exception");
XCTAssertFalse([session isAuthorized],
@"Public key authentication with invalid password should not"
@"work");
}
- (void)testPublicKeyAuthenticationWithInvalidKeyFails {
NSString *host = [validPublicKeyProtectedServer objectForKey:@"host"];
NSString *username = [validPublicKeyProtectedServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"invalid_public_key"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPublicKey:publicKey
privateKey:[publicKey stringByDeletingPathExtension]
andPassword:nil],
@"Authentication with invalid public key doesn't throw"
@"exception");
XCTAssertFalse([session isAuthorized],
@"Authentication with invalid public key should not work");
}
- (void)testPublicKeyAuthenticationWithInvalidUserFails {
NSString *host = [validPublicKeyProtectedServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"valid_public_key"];
NSString *password = [validPublicKeyProtectedServer
objectForKey:@"password"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session authenticateByPublicKey:publicKey
privateKey:[publicKey stringByDeletingPathExtension]
andPassword:password],
@"Public key authentication with invalid user doesn't"
@"throw exception");
XCTAssertFalse([session isAuthorized],
@"Public key authentication with invalid user should not work");
}
- (void)testValidConnectionToAgent {
NSString *host = [validAgentServer objectForKey:@"host"];
NSString *username = [validAgentServer objectForKey:@"user"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session connectToAgent],
@"Valid connection to agent doesn't throw exception");
XCTAssertTrue([session isAuthorized],
@"Agent authentication with valid username should work");
}
- (void)testInvalidConnectionToAgent {
NSString *host = [validAgentServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];
session = [NMSSHSession connectToHost:host withUsername:username];
XCTAssertNoThrow([session connectToAgent],
@"Invalid connection to agent doesn't throw exception");
XCTAssertFalse([session isAuthorized],
@"Agent authentication with invalid username should not"
@"work");
}
// -----------------------------------------------------------------------------
// CONFIG TESTS
// -----------------------------------------------------------------------------
// Tests synthesis that uses some defaults, some global, and some local values,
// and merges identity files.
- (void)testConfigSynthesisFromChain {
NMSSHConfig *globalConfig = [[NMSSHConfig alloc] initWithString:
@"Host host\n"
@" Hostname globalHostname\n"
@" Port 9999\n"
@" IdentityFile idFile1\n"
@" IdentityFile idFile2"];
NMSSHConfig *userConfig = [[NMSSHConfig alloc] initWithString:
@"Host host\n"
@" Hostname localHostname\n"
@" IdentityFile idFile2\n"
@" IdentityFile idFile3"];
NSArray *configChain = @[ userConfig, globalConfig ];
session = [[NMSSHSession alloc] initWithHost:@"host"
configs:configChain
withDefaultPort:22
defaultUsername:@"defaultUsername"];
XCTAssertEqualObjects(session.hostConfig.hostname, @"localHostname",
@"Hostname not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.port, @9999,
@"Port not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.user, @"defaultUsername",
@"User not properly synthesized");
NSArray *expected = @[ @"idFile2", @"idFile3", @"idFile1" ];
XCTAssertEqualObjects(session.hostConfig.identityFiles, expected,
@"Identity files not properly synthesized");
}
// Tests that all default values can appear in the synthesized config.
- (void)testConfigSynthesisInheritsDefaults {
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:
@"Host nonMatchingHost\n"
@" Hostname badHostname\n"
@" Port 9999\n"
@" User badUser\n"
@" IdentityFile badIdFile\n"];
NSArray *configChain = @[ config ];
session = [[NMSSHSession alloc] initWithHost:@"goodHost"
configs:configChain
withDefaultPort:22
defaultUsername:@"goodUsername"];
XCTAssertEqualObjects(session.hostConfig.hostname, @"goodHost",
@"Hostname not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.port, @22,
@"Port not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.user, @"goodUsername",
@"User not properly synthesized");
NSArray *expected = @[ ];
XCTAssertEqualObjects(session.hostConfig.identityFiles, expected,
@"Identity files not properly synthesized");
}
// Tests that all values respect the priority hierarchy of the config chain.
- (void)testConfigSynthesisRespectsPriority {
NMSSHConfig *globalConfig = [[NMSSHConfig alloc] initWithString:
@"Host host\n"
@" Hostname globalHostname\n"
@" Port 9999\n"
@" User globalUser"];
NMSSHConfig *userConfig = [[NMSSHConfig alloc] initWithString:
@"Host host\n"
@" Hostname localHostname\n"
@" Port 8888\n"
@" User localUser"];
NSArray *configChain = @[ userConfig, globalConfig ];
session = [[NMSSHSession alloc] initWithHost:@"host"
configs:configChain
withDefaultPort:22
defaultUsername:@"defaultUsername"];
XCTAssertEqualObjects(session.hostConfig.hostname, @"localHostname",
@"Hostname not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.port, @8888,
@"Port not properly synthesized");
XCTAssertEqualObjects(session.hostConfig.user, @"localUser",
@"User not properly synthesized");
}
// Tests that values from the config are used in creating the session.
- (void)testConfigIsUsed {
NMSSHConfig *config = [[NMSSHConfig alloc] initWithString:
@"Host host\n"
@" Hostname configHostname\n"
@" Port 9999\n"
@" User configUser\n"];
NSArray *configChain = @[ config ];
session = [[NMSSHSession alloc] initWithHost:@"host"
configs:configChain
withDefaultPort:22
defaultUsername:@"defaultUsername"];
XCTAssertEqualObjects(session.host, @"configHostname",
@"Hostname from config not used");
XCTAssertEqualObjects(session.port, @9999,
@"Port from config not used");
XCTAssertEqualObjects(session.username, @"configUser",
@"User from config not used");
}
@end

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>
@interface ConfigHelper : NSObject
/**
* Helper method to get a value from the configuration YAML.
*
* Assuming the values in the YAML file can be represented as NSDictionary, you
* can create a chain to get a deep value.
*
* Example:
*
* NSString *host = [ConfigHelper valueForKey:
* @"valid_password_protected_server.host"];
*/
+ (id)valueForKey:(NSString *)key;
@end

View File

@@ -0,0 +1,28 @@
#import "ConfigHelper.h"
#import <YAML/YAMLSerialization.h>
@implementation ConfigHelper
+ (id)valueForKey:(NSString *)key {
static id yaml;
if (!yaml) {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSString *path = [bundle pathForResource:@"config" ofType:@"yml"];
NSInputStream *stream = [[NSInputStream alloc] initWithFileAtPath:path];
yaml = [YAMLSerialization YAMLWithStream:stream
options:kYAMLReadOptionStringScalars
error:nil];
}
id data = [yaml objectAtIndex:0];
NSArray *keyList = [key componentsSeparatedByString:@"."];
for (NSString *keyPart in keyList) {
data = [data objectForKey:keyPart];
}
return data;
}
@end

View File

@@ -0,0 +1,47 @@
# Defines a valid, password protected server, and options for testing both
# valid and invalid user/password combinations as well as SCP to both a
# writable directory and one that is not writable by the user
valid_password_protected_server:
host: "127.0.0.1:22"
# User config
user: "user"
password: "password"
# Shell execution config
execute_command: "ls -1 /var/www/nmssh-tests/"
execute_expected_response: "invalid\nvalid\n"
# Directory config
writable_dir: "/var/www/nmssh-tests/valid/"
non_writable_dir: "/var/www/nmssh-tests/invalid/"
# Defines a valid, public key protected server, and options for testing both
# valid and invalid user/password combinations as well as SCP to both a
# writable directory and one that is not writable by the user
valid_public_key_protected_server:
host: "127.0.0.1:22"
# User config
user: "user"
# Public key path
valid_public_key: "~/.ssh/id_rsa.pub"
invalid_public_key: "~/.ssh/github_rsa.pub"
# Public key password
password: "password"
# Defines a valid server, that this computer can connect to via an agent.
valid_agent_server:
host: "127.0.0.1:22"
# User config
user: "user"
# Defines an invalid server and authentication credentials that are invalid for
# all defined test servers
invalid_server:
host: "0.0.0.0:22"
user: "user"
password: "pass"

View File

@@ -0,0 +1 @@
Versions/Current/Headers

View File

@@ -0,0 +1 @@
Versions/Current/Resources

View File

@@ -0,0 +1,58 @@
//
// YAMLSerialization.h
// YAML Serialization support by Mirek Rusin based on C library LibYAML by Kirill Simonov
// Released under MIT License
//
// Copyright 2010 Mirek Rusin
// Copyright 2010 Stanislav Yudin
//
#import <Foundation/Foundation.h>
#import "yaml.h"
// Mimics NSPropertyListMutabilityOptions
typedef enum {
kYAMLReadOptionImmutable = 0x0000000000000001,
kYAMLReadOptionMutableContainers = 0x0000000000000010,
kYAMLReadOptionMutableContainersAndLeaves = 0x0000000000000110,
kYAMLReadOptionStringScalars = 0x0000000000001000
} YAMLReadOptions;
typedef enum {
kYAMLErrorNoErrors,
kYAMLErrorCodeParserInitializationFailed,
kYAMLErrorCodeParseError,
kYAMLErrorCodeEmitterError,
kYAMLErrorInvalidOptions,
kYAMLErrorCodeOutOfMemory,
kYAMLErrorInvalidYamlObject,
} YAMLErrorCode;
typedef enum {
kYAMLWriteOptionSingleDocument = 0x0000000000000001,
kYAMLWriteOptionMultipleDocuments = 0x0000000000000010,
} YAMLWriteOptions;
extern NSString *const YAMLErrorDomain;
@interface YAMLSerialization : NSObject {
}
+ (void) writeYAML: (id) yaml
toStream: (NSOutputStream *) stream
options: (YAMLWriteOptions) opt
error: (NSError **) error;
+ (NSData *) dataFromYAML: (id) yaml
options: (YAMLWriteOptions) opt
error: (NSError **) error;
+ (NSMutableArray *) YAMLWithStream: (NSInputStream *) stream
options: (YAMLReadOptions) opt
error: (NSError **) error;
+ (NSMutableArray *) YAMLWithData: (NSData *) data
options: (YAMLReadOptions) opt
error: (NSError **) error;
@end

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>11E53</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>YAML</string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.YAML</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>YAML</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>DTCompiler</key>
<string></string>
<key>DTPlatformBuild</key>
<string>4E3002</string>
<key>DTPlatformVersion</key>
<string>GM</string>
<key>DTSDKBuild</key>
<string>11E53</string>
<key>DTSDKName</key>
<string></string>
<key>DTXcode</key>
<string>0433</string>
<key>DTXcodeBuild</key>
<string>4E3002</string>
</dict>
</plist>

View File

Binary file not shown.

View File

@@ -0,0 +1 @@
A

View File

@@ -0,0 +1 @@
Versions/Current/YAML