Skip to content
Open
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
34 changes: 33 additions & 1 deletion Service/Sources/EDOHostNamingService.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@
#import "Service/Sources/EDOHostService.h"
#import "Service/Sources/EDOServicePort.h"

@interface EDOHostNamingServiceProxy : NSObject
- (instancetype)initWithNamingService:(EDOHostNamingService *)namingService;
@end

@implementation EDOHostNamingServiceProxy {
__weak EDOHostNamingService *_namingService;
}

+ (BOOL)accessInstanceVariablesDirectly {
return NO;
}

- (instancetype)initWithNamingService:(EDOHostNamingService *)namingService {
self = [super init];
if (self) {
_namingService = namingService;
}
return self;
}

- (UInt16)portForServiceWithName:(NSString *)name {
return [_namingService portForServiceWithName:name];
}

- (UInt16)serviceConnectionPort {
return _namingService.serviceConnectionPort;
}

@end

@implementation EDOHostNamingService {
// The mapping from service name to host service port.
NSMutableDictionary<NSString *, EDOServicePort *> *_servicePortsInfo;
Expand Down Expand Up @@ -84,8 +114,10 @@ - (BOOL)start {
if (self->_service) {
return;
}
EDOHostNamingServiceProxy *proxy =
[[EDOHostNamingServiceProxy alloc] initWithNamingService:self];
self->_service = [EDOHostService serviceWithPort:EDOHostNamingService.namingServerPort
rootObject:self
rootObject:proxy
queue:self->_namingServiceEventQueue];
result = self->_service.port.hostPort.port != 0;
});
Expand Down
31 changes: 31 additions & 0 deletions Service/Tests/UnitTests/EDOHostNamingServiceTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ - (void)testStartEDONamingServiceObject {
XCTAssertEqual([namingService portForServiceWithName:kDummyServiceName], kDummyServicePort);
}

/** Verifies that remote invocation of private mutators throws an exception. */
- (void)testRemoteInvocationOfPrivateMutatorThrowsException {
[EDOHostNamingService.sharedService start];
id remoteNamingService =
[EDOClientService rootObjectWithPort:EDOHostNamingService.namingServerPort];

// addServicePort: is a private mutator and should not be available remotely when using proxy.
EDOServicePort *dummyPort = [EDOServicePort servicePortWithPort:12345
serviceName:@"com.google.poison"];
XCTAssertThrows([remoteNamingService addServicePort:dummyPort]);
}

/** Verifies that remote invocation of stop throws an exception. */
- (void)testRemoteInvocationOfStopThrowsException {
[EDOHostNamingService.sharedService start];
id remoteNamingService =
[EDOClientService rootObjectWithPort:EDOHostNamingService.namingServerPort];

// stop is a lifecycle method and should not be available remotely when using proxy.
XCTAssertThrows([remoteNamingService stop]);
}

/** Verifies that remote invocation of serviceConnectionPort works. */
- (void)testRemoteInvocationOfServiceConnectionPort {
[EDOHostNamingService.sharedService start];
id remoteNamingService =
[EDOClientService rootObjectWithPort:EDOHostNamingService.namingServerPort];

XCTAssertNotEqual([remoteNamingService serviceConnectionPort], 0);
}

/**
* Tests sending object request to the naming service after stopping it, and verifies that
* exception happens.
Expand Down