|
|
|
There appear to be a few issues with Safari and RC.
1) The java server isn't creating a proxy config when it starts up Safari 2) I don't know of a way to programatically change the proxy settings even if it was 3) Creating a proxy config by hand and setting the system to use it still doesn't work. It gets past the 404 error but then it hangs and eventually terms with a timeout. server console output: console output running test using Ruby client 1) Error: 1 tests, 0 assertions, 0 failures, 1 errors We can currently launch Safari just fine, but we still don't yet know how to auto-configure the proxy on Safari.
Frustratingly, we still have no leads on how to make this work. If anybody has any idea as to how to configure the Safari proxy using command line tools, I'd appreciate a tip!
I forgot to mention: we do have a mini lead which may be enough if we want to try it: the command line tool "ncutil" can probably do the job. We could probably require people to install ncutil and then detect it on the path or in a standard location, like we do for reg.exe on Windows 2000. Not that we even know if this works or not...
"Introduction to System Configuration Programming Guidelines":
http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/index.html?http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_UnderstandSchema/chapter_4_section_2.html MoreSCF: Network settings – including the HTTP proxy – are stored on the file system in the following location: Some remarks on researching this:
My test for whether I've configured a proxy or not is simply to try setting the proxy to "http://www.google.com". When I do that with the Network Preferences control panel, Safari fails to load any pages (including Google). I'm able to use the control panel to do this while Safari is running: check the box, Apply Now, refresh in Safari... homepage is broken. Uncheck the box, Apply Now, refresh in Safari... homepage works again. Relevant threads on the macnetworkprog list: 1) ncutil seems to do the job, but you have to be root to use it to modify settings. (sudo is fine, of course.) Furthermore, if you want your settings to sink in prior to reboot, you have to restart configd. The only way to restart configd is to kill it and relaunch it as root. There's some documentation suggesting that configd is supposed to automatically notice changes to preferences.plist, but I can't reproduce that. Even if we did require everybody to install ncutil, I'm not sure if I like the requirement that we run our software as root/sudo in order for us to automatically configure Safari's proxy. 2) as far as I can tell, scutil is a useful tool for reading settings, but its API for actually setting the settings doesn't appear to have any effect on anything, contrary to what Allan suggests in those threads. scutil not only fails to update settings in the Network Preferences control panel, but it fails to modify Safari's proxy settings, regardless of whether Safari is running or not. This seems to contradict Allan's suggestion that scutil modifies the settings of running applications. If scutil has some effect on some other program that isn't Safari, I can't see what it might be. Here's what I'm doing: open The settings seem to persist when I quit/relaunch scutil, but they have no effect on Safari. It's a shame to force the tester to be root, but that would still be a big improvement over requiring manual config of the browser, IMO.
The Month of Apple Bugs included an enlightening local escalation exploit, that helped me understand how the Preferences control panel works without requiring a root password.
http://projects.info-pull.com/moab/MOAB-21-01-2007.html This blog entry explains the more general case: http://elliotth.blogspot.com/2006_03_01_elliotth_archive.html "I've complained a few times about the number of setuid binaries on Mac OS. Various things that Linux manages to do via /proc, for example, Mac OS does via root-only API, and ships setuid binaries as helpers for those programs (such as Activity Monitor) that need the API nonetheless." The writeconfig app and the NetCfgTool are both setuid. We may be able to use them (in their intended way, non-exploitatively) to set the network proxy on Safari without requiring a root password. Another day, another extra bit of research.
The System Preferences Control Panel absolutely uses NetCfgTool to do its dirty work (i.e. to set the network proxy as a non-root user). If you watch it in top, you can see that NetCfgTool isn't running when you start System Preferences, but it gets launched by System Preferences when you click on the "Network" button. If you rename NetCfgTool so it's unavailable, you'll find that all network settings in the Network control panel are greyed out; you're unable to set them. I had hoped that System Preferences was launching NetCfgTool with some command line arguments, but that's not apparently the way it works. (I tried renaming NetCfgTool to NetCfgToolx, putting in its place a simple bash script that logs command line arguments then calls NetCfgToolx. The log clearly showed no command line arguments.) Apparently, System Preferences just leaves NetCfgTool running, and then somehow communicates with NetCfgTool using some kind of IPC mechanism. I don't know what that mechanism may be. Notably, a dude in this forum claims that you need to launch NetCfgTool in order to run scselect from the command line: I tried it and then tried running scutil from the command line, to see if I could get scutil to actually do anything, but it didn't work. I still have no evidence that scutil can set any setting whatsoever... scutil seems to be a totally useless app as far as I can tell. My current best guess is that we would either: 1) require the end user to install ncutil and then ship a script that the end user should install setuid root, and then shell out to that script at runtime, or With that said, I'm going to go out on a limb and guess that we're not supposed to be doing that: I believe some Apple apps communicate startup parameters using Apple Events. But I'm far from an Apple guru – I wish one of those would take an interest in this problem.
Anyway, it would be nice if we could monitor and track Apple Events, and see if that is the IPC mechanism being used in this case. So I think I found a way to do it.
$ /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -help This has options like: also has setsecurewebproxy[state] <networkservice> is one of (on my box): So for me, I was able to invoke these commands, and then verified the settings in the Network Sys Pref panel, and also verified that Safari either worked (with proxystate to off) or did not I think I might start to work on a patch... I am rather unfamiliar with your codebase however, where would this sort of command-line stuff go? That is fantastic news, Thomas.
We are already using some process spawning code in the browser launcher code. Look at the users of the AsyncExecute module in org.openqa.selenium.server.browserlaunchers (though of course I don't think you'll want to be asynchronous in this case; AsyncExecute is a child of Execute, which may well be the way to go for you). Awesome find, Thomas. I confirm that it appears to work even as non-root.
But beware: on my 10.4.5 machine, you won't find "networksetup" in /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/. Instead, on my box it appears to be called "networksetup-panther"! That may make things a bit trickier... maybe look for an executable whose name starts with "networksetup"? Another question... it doesn't seem like networksetup can tell whether a given network service is actually in use. For example, right now I'm on wifi ("AirPort"), with no ethernet cable plugged in to the jack. Yet it still lists all of the networkservices as "Enabled"... I suppose none of them are explicitly disabled. Do we therefore have to set the appropriate web proxies on all of the network services (looping over them one-by-one), restoring them safely after the fact?
Oh, and to address your earlier question, I would compare/contrast OS X "networksetup" support with our implementation of Windows registry support for IE; many of the problems that apply there would apply here also. We need to shell out to call reg.exe on Windows to do our work; we need to use it to back up the settings before we modify them, and we need to safely restore those settings when we're cleaning up. If we crash before we can clean up, we need to be clever enough not to overwrite the old backup, and to restore the old backup safely if/when we finally do get a chance to clean up. This may be a lot to bite off at once... Even a starter patch would be much appreciated! Okay, so on my PowerPC Tiger machine (10.4.8), networksetup is a symlink to networksetup-tiger. On my Intel Tiger Machine (10.4.9), networksetup is a symlink to networksetup-panther. Odd indeed. Basically, I am figuring on doing some magic to determine the OS X version, then using it to pick newest networksetup available on the machine, in correspondence to the version of the OS you're using. E.G. for my intel box, i'd see OS X version 10.4, so (using a mapping of os x version to os x codename (4-tiger, 3-panther, 2-jaguar, 1-puma) etc. (making sure I make it compatible with leopard
-Tom PS> Can someone else with a Mac who reads this verify that you really really don't need to be root to do this? I read somewhere that changing the params really does require sudo access... I am thinking that might be true in the event that the users have the 'Click the Lock to make changes.' set in Network Preferences. Which, if that is the case, then they would have to unlock that to manually change it anyway, so I'm okay proceeding... I can absolutely verify that you really really don't need to be root. I even know how the magic trick works: running networksetup-panther launches NetCfgTool, the setuid-root binary I discussed earlier in this bug thread. I just confirmed this on my 10.4 intel Mac a minute ago.
Thanks again, Thomas, for looking into this. -Dan I have a patch that is almost working. I just need to make sure that I clean up after myself, and then start testing on various network configurations.
-Tom No need to make this patch perfect on the first try... If you can send over something, then we can get more people involved in testing it. Thanks again!
Tom sent me this patch in private e-mail; it seems to be useful on my machine.
I think even with the patch I won't be able to fix this anytime this week, so I'm bumping this to 0.9.3. (We're close, though!)
gist: The patch did not seem to fix the proxy issue when testing selenium trunk (r1876) on osX-10.4.10 (PPC) – There were other issues with trunk and OSX which I am looking into.
This is as much of a test of the selenium trunk as the patch. I'm not an OSX person, nor a Selenium expert or maven expert. The latest version of networksetup on my system is networksetup-panther... which seems to add to the versioning annoyances above. I needed to make a symlink from networksetup to networksetup-panther. 0. got trunk TEST 1: Safari would do the same thing it did under the release version, that is startup and display a 404 All tests would halt after the following message, not related to the patch. I'm looking into these. >All tests would halt after the following message, not related to the patch. I'm looking into these.
>[INFO] 10:27:19,586 INFO [org.mortbay.http.SocketListener] LOW ON THREADS ((512-511+0)<2) on SocketListener0@0.0.0.0:4444 >[INFO] 10:28:19,630 WARN [org.mortbay.util.ThreadPool] No thread for Socket[addr=/127.0.0.1,port=57432,localport=4444] I independantly discovered the networksetup trick to set the proxy and implemented it in a shell script that I am wrapping selenium rc calls in. However, the above error is very consistent. I tried running the server with "-jettyThreads 1024" which caused out of memory errors, so I increased my heap size to 256M and voila, I got the same error message but that contained I also thought the problem might be in my jre but I have tried with both 1.5.0 and 1.6.0-dp and neither made any difference save for modifying the error message slightly. I'm on OS X 10.4.10, kernel version Darwin 8.10.0 PPC I've been testing with the latest selenium-server-0.9.2 snapshot as of this morning, a 0.9.1 snapshot from July and the 0.9.0 release. Tom Rybka has apparently misplaced his JIRA login credentials, but he told me to post this:
The RC server has to be started with the following options (assuming you want pimode) java -jar -Dhttp.proxyHost='' -Dhttp.proxyPort='' selenium-server-0.9.2-SNAPSHOT-standalone.jar -proxyInjectionMode -forcedBrowserMode '*safari'" The reason for the proxyHost and proxyPort is that once you've started the system-wide proxy with networksetup, Java will try to route even your Selenium traffic through it, back through itself, and you'll run out of threads. If you set the proxyHost and proxyPort to '', then Java will not use a proxy, and it will work just fine(ish). I was asked to post the script I'm using to set the proxy for Safari. This is the gist of it.
/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setwebproxy "Airport" localhost 4444 java -jar -Dhttp.proxyHost="" -Dhttp.proxyPort="" "selenium-server-0.9.2.jar" -userExtensions "user-extensions.js" -htmlSuite "*safari" "http://...." "TestSuite.html" "ResultsFile.html" /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setwebproxystate "Airport" off This is now working for me. Still haven't finished wiring up our "networksetup" support (and that still probably won't make it in to 0.9.2), but I've added code in RC revision 1995 to detect an infinite proxy loop (where Java's http.proxyHost is localhost and the http.proxyPort is the exact same port as the Selenium Server port) and to automatically force the .proxyHost to be "" in that case. This should increase the likelihood that people will successfully configure RC on OS X.
As of today, at least on my machines, the -setwebproxy command fails with the following error:
$ /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup -setwebproxy "Built-in Ethernet" localhost 4444 Here's some more info on that file: Tested on a fully patched Mac Pro desktop and MacBook Pro laptop. I'm starting to think a long term solution here will be AppleScript based. (At least until Apple requires sudo access to modify the network preferences GUI.) I'm not sure I believe this. That message "preferences.plist.old: Permission denied" is a WARNING, not an error. I see it on my iMac when the command is definitely working correctly. Check your Control Panel to confirm it.
Don't forget that it's very easy for people to think that they've configured their proxy correctly when, in fact, they're confused about which setting they really need to set and where to look to see if their commands had the expected results. For example, people think they're using Built-In Ethernet when in fact they're using AirPort, or vice versa. IMO, AppleScript is not the way to go here. AppleScript requires automating the UI of the Control Panel, including parsing the Control Panel GUI to enumerate the available network services, back up their settings, and then modify them safely. I can't believe that's the right answer here, relative to some other command-line based solution. Even writing our own proxy configuration program in C would likely be a better way to go. Okay... (blushing)... I swear I double-checked this before posting, but you're right... it's a warning, not an error. Well, at least the bit about the warning is documented now. :-/
Regarding the AppleScript vs C comment... well no comment, since networksetup is in fact working for me. I've been engaging in a long e-mail conversation with Allan, an engineer at Apple, who has helped me work through a few of these key issues. (A few of his posts on lists.apple.com are linked in the discussion above.) I'll summarize a few key points about what I've learned:
0) scutil really shouldn't be used for writing the proxy settings, but it is an effective way of reading the current effective settings out of the dynamic store. For example, you can determine the current "primary" interface (e.g. "en0") as well as the primary network service name (used for networksetup) by using "show State:/Network/Global/IPv4". 1) It may seem as if it's possible to configure network settings as non-root without using a password, but in fact to get it to work you need to be an "admin user." Even the setuid root tool NetCfgTool requires "admin" privs. The wrinkle is that most Mac systems have a single user who has these privs and the "lock" is generally open. If you go to Network Prefs and close the lock then you should get a prompt when attempting to use networksetup. 2) As we already knew, there are many varieties of "networksetup" out there in the wild, at least some of which are unable to configure certain proxy settings. In particular, some versions of networksetup have commands to "-getautoproxyurl" "-setautoproxyurl" and "-setautoproxystate", whereas other versions of networksetup don't have this feature. (In particular, on the Intel 10.4.10 iMac I've got here at work, it does NOT have that feature.) 3) NetCfgTool will be "essentially gone" post-Tiger. 4) All this made me want to research ncutil again. I found that ncutil 3.1 doesn't immediately affect configd unless you "nudge" it with the "apply-changes" command. You can also pass the "--apply-on-exit" option to do the same thing. These commands will affect the currently running Safari just the way you'd expect: sudo ncutil --apply-on-exit setprop "/Automatic/Built-in Ethernet/Proxies" http-proxy-enable 0 ncutil is easily able to modify all of the proxy settings, including the auto proxy url. 5) Using a VPN can really screw up the whole thing. We use the Cisco VPN for OS X here on the Mac at work, and I found that the VPN appears to "capture" the proxy settings when the VPN connects. Once the VPN is on/connected, nothing you can do will change the proxy settings, even when you change them manually using the Network Control Panel. For example, you can set the proxy manually to www.google.com:80, then start Safari, and find that every site looks like Google. Then start the Cisco VPN and finally turn off the HTTP proxy. You'll find that every site will still look like Google until you disconnect the VPN, at which point your network will resume paying attention to the proxy settings you configured in the control panel. I almost forgot the conclusion of all this... I've got some running code that kinda sorta works now, assuming you don't use a VPN (SRC-366) or configure a proxy PAC file (SRC-364) or use SSL (SRC-367 and SRC-141). It backs up the network settings using Java Preferences and restores them during test cleanup.
IMO, what we should do on top of this is write a shell script that wraps around ncutil and uses it to write out HTTP proxy settings. We should make it simple and write it in a highly defensive style, and advocate to our users that they install this script on their path with setuid root. Then, for our part, we should look to see if the script is available (perhaps adding [ulp] yet another command line argument) as well as ncutil. If we find everything we need, we use ncutil for everything. (ncutil is BSD code, and so I suppose we could just provide it ourselves, but I think installing it requires root access, and creating that setuid root script would DEFINITELY require root access; ideally, I'd like not to have to run the whole Selenium Server as root just to configure the proxy settings.) If ncutil is not available, we should fall back to using scutil + networksetup. (We should query networksetup to see if it supports configuring PAC files and use that functionality if it's available.) If networksetup isn't available, then we should fail with a link to a web page explaining our situation, like the one we've already got for Windows reg.exe issues: http://wiki.openqa.org/display/SRC/Windows+Registry+Support As you can tell, there's a LOT of special cases for this code; I made sure that I unit tested the hell out of the code I've already checked in, and there's still way more code not yet written that will need a similar treatment. |
||||||||||||||||||||||||||||||||||||||||||||||||||||
SRC-29:This is definately going to need AppleScript experience.
http://www.apple.com/applescript/safari/
open -a /Applications/Safari.app http://google.com
opens the default browser not Safari.