Skip to content

Commit

Permalink
Cleanup trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Lejdborg committed Jun 30, 2012
1 parent 6cc5abf commit 1dfce6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
14 changes: 7 additions & 7 deletions NMSSH/NMSSHSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,33 @@ - (BOOL)authenticateByPublicKey:(NSString *)publicKey
// Check what authentication methods are available
char *userauthlist = libssh2_userauth_list(session, [username UTF8String],
strlen([username UTF8String]));

if (strstr(userauthlist, "publickey") == NULL) {
NSLog(@"NMSSH: Authentication by public key not available for %@", host);
return NO;
}

if (password == nil) {
password = @"";
}

// Get absolute paths for private/public key pair
publicKey = [publicKey stringByExpandingTildeInPath];
NSString *privateKey = [publicKey stringByReplacingOccurrencesOfString:@".pub"
NSString *privateKey = [publicKey stringByReplacingOccurrencesOfString:@".pub"
withString:@""];

// Try to authenticate with key pair and password
int error = libssh2_userauth_publickey_fromfile(session,
[username UTF8String],
[publicKey UTF8String],
[privateKey UTF8String],
[password UTF8String]);

if (error) {
NSLog(@"NMSSH: Public key authentication failed");
return NO;
}

authorized = YES;
return [self isAuthorized];
}
Expand Down
40 changes: 21 additions & 19 deletions NMSSHTests/NMSSHSessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (void)testConnectionToValidServerWorks {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [validPasswordProtectedServer
objectForKey:@"user"];

STAssertNoThrow(session = [NMSSHSession connectToHost:host
withUsername:username],
@"Connecting to a valid server does not throw exception");
Expand All @@ -53,7 +53,7 @@ - (void)testConnectionToValidServerWorks {
- (void)testConnectionToInvalidServerFails {
NSString *host = [invalidServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];

STAssertNoThrow(session = [NMSSHSession connectToHost:host
withUsername:username],
@"Connecting to a invalid server does not throw exception");
Expand All @@ -72,7 +72,7 @@ - (void)testPasswordAuthenticationWithValidPasswordWorks {
objectForKey:@"user"];
NSString *password = [validPasswordProtectedServer
objectForKey:@"password"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPassword:password],
Expand All @@ -88,7 +88,7 @@ - (void)testPasswordAuthenticationWithInvalidPasswordFails {
NSString *username = [validPasswordProtectedServer
objectForKey:@"user"];
NSString *password = [invalidServer objectForKey:@"password"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPassword:password],
Expand All @@ -103,13 +103,13 @@ - (void)testPasswordAuthenticationWithInvalidUserFails {
NSString *host = [validPasswordProtectedServer objectForKey:@"host"];
NSString *username = [invalidServer objectForKey:@"user"];
NSString *password = [invalidServer objectForKey:@"password"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPassword:password],
@"Authentication with invalid username/password doesn't"
@"throw exception");

STAssertFalse([session isAuthorized],
@"Authentication with invalid username/password should not"
@"work");
Expand All @@ -122,14 +122,14 @@ - (void)testPublicKeyAuthenticationWithValidKeyWorks {
objectForKey:@"valid_public_key"];
NSString *password = [validPublicKeyProtectedServer
objectForKey:@"password"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPublicKey:publicKey
andPassword:password],
@"Authentication with valid public key doesn't throw"
@"exception");

STAssertTrue([session isAuthorized],
@"Authentication with valid public key should work");
}
Expand All @@ -139,14 +139,14 @@ - (void)testPublicKeyAuthenticationWithInvalidPasswordFails {
NSString *username = [validPublicKeyProtectedServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"valid_public_key"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPublicKey:publicKey
andPassword:nil],
@"Public key authentication with invalid password doesn't"
@"throw exception");

STAssertFalse([session isAuthorized],
@"Public key authentication with invalid password should not"
@"work");
Expand All @@ -158,14 +158,14 @@ - (void)testPublicKeyAuthenticationWithInvalidKeyFails {
NSString *username = [validPublicKeyProtectedServer objectForKey:@"user"];
NSString *publicKey = [validPublicKeyProtectedServer
objectForKey:@"invalid_public_key"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPublicKey:publicKey
andPassword:nil],
@"Authentication with invalid public key doesn't throw"
@"exception");

STAssertFalse([session isAuthorized],
@"Authentication with invalid public key should not work");
}
Expand All @@ -177,16 +177,18 @@ - (void)testPublicKeyAuthenticationWithInvalidUserFails {
objectForKey:@"valid_public_key"];
NSString *password = [validPublicKeyProtectedServer
objectForKey:@"password"];

session = [NMSSHSession connectToHost:host withUsername:username];

STAssertNoThrow([session authenticateByPublicKey:publicKey
andPassword:password],
@"Public key authentication with invalid user doesn't"
@"throw exception");

STAssertFalse([session isAuthorized],
@"Public key authentication with invalid user should not work");
}

@end
// TODO: Create tests for SSH agent

@end

0 comments on commit 1dfce6d

Please sign in to comment.