Re: Permission Denied trying to connect to localhost in unit test
Re: Permission Denied trying to connect to localhost in unit test
- Subject: Re: Permission Denied trying to connect to localhost in unit test
- From: Robert Walsh via Cocoa-dev <email@hidden>
- Date: Fri, 13 Dec 2019 14:42:18 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=envisionware.com; dmarc=pass action=none header.from=envisionware.com; dkim=pass header.d=envisionware.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rZ1n5Z7dycouIpSVFVYiyJfrZqJoCRTYSd4ec1WIyt8=; b=jewjpBedy0rTDpmU0d74nRAQiL5vSffpb58LIZwfLYn8zJw93vc2BpbTCWl2UUsJcDErCvJ1xwDudgOOJLgIfXPjd9CrOSf8ZRvK+OWmwJm4MT/Spm2IDVuEqg4Q0sP6ketCbdxuEEvckRNfs6aUdXuO0+PU6YTaULTY4mltF87S9NJCBhQbfX1GT2018tsLQEAIw2WK8wSRbDptQgyaM5cxeJiVzr4+WExPsoVcCoaHr4FKTEk9ajEEHuvO4qdyAr5To3QNmOkXww5lYrihyxUi+X01iyfo1fGbhxnhRbM7OAX8CM+4nPMi2rABqRXgeG14D+6OoPVLhDzrZHO8Ig==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZdhFxV/dM4k2vTODh8nX/OczpXtE5kR6spH3PJNTU5YoqhgDzOY72yquWkBDJZDoaF2wCELUqG7E6EtZXYbWmPnA6R/2sZ1lq4A2JuSXopdrN8SNzI7yeIV7/rXz81V2mfmP+YINLp5KLatVc0dqjQyH3XhwFLBTEN9am9sn82FjkzgB7zFKlHtwKb8XrPfnwx2BojEI98+3wsQ5vIy1nyBNcrrjvgEsqg3KITPU9QFeQtxof9VknENdlWSxLjoW2gvwjoe1rId06K5m6ALwUqMV1xxDpAy5Pi6y8nLBxWq9uUK/GPyGznpkJzm2ovwJy1aLQcLPFnBqdsfjOBC3sw==
- Thread-topic: Permission Denied trying to connect to localhost in unit test
The errno is 13 (which I think is just a generic Permission Denied).
I am connecting to localhost.
I did find this post in the Apple Developer Forums
(https://forums.developer.apple.com/thread/52211):
How do I unittest a command line application? |Apple Developer
Forums<https://forums.developer.apple.com/thread/52211>
Yes, you can add the unit testing bundle, but it won't let you set Target to be
Tested.. Right. That’s because the machinery to load your test bundle within a
process only works if the process is based on a GUI framework (like Cocoa or
Cocoa Touch).
forums.developer.apple.com
A command line tool typically does not use a GUI framework and thus the test
machinery is unable to load your bundle into that tool.
However, you can test without an app target. If you set the Target to be
Tested popup to None, Xcode will load your test bundle into its built-in ‘test
runner’ tool, xctest.
This works well for most but there are some gotchas. Specifically, if the code
you’re using requires entitlements then you won’t be able to test it like this
because there’s no way to give those entitlements to xctest. The standard
workaround for that is to add a dummy test target app to your project.
Assuming the problem is that I need to add the App Sandbox -> Outgoing
Connections (Client) entitlement to the command line target (since I can't add
any entitlements to the test target; clicking "+ Capabilities" brings up a
dialog saying that capabilities are not support for this target), how do I
create "a dummy test target app?" As I said before, I created the test target
by using the Unit Test Bundle template, and I don't see any other relevant
choices.
Rob
________________________________
From: Jens Alfke <email@hidden>
Sent: Thursday, December 12, 2019 1:58 PM
To: Robert Walsh <email@hidden>
Cc: Cocoa-Dev (Apple) <email@hidden>
Subject: Re: Permission Denied trying to connect to localhost in unit test
On Dec 12, 2019, at 7:42 AM, Robert Walsh via Cocoa-dev
<email@hidden<mailto:email@hidden>> wrote:
I am writing a command line application in Objective-C that needs to make a TCP
connection to a server. In a unit test for the TcpClient class I am writing, I
have a simple TCP server that listens for connections in a thread. When I try
to connect to this socket from the client socket class, connect() fails and
perror reports Permission Denied.
That's odd. I've written plenty of macOS networking code and not seen this
problem. What is the errno value?
The only thing I can guess is that the Xcode test-runner process is being
sandboxed to prevent outgoing networking, but I've definitely run TCP
connections from XCTests without problems. Are you connecting to "localhost" /
127.0.0.1, or using an explicit IP address?
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden