Skip to content
Browse files

bugfix: network services with spaces

  • Loading branch information...
1 parent 304970e commit 7b27047c99cd36ac7d944bc0415aa61f0abd84de @elentok committed Mar 6, 2013
Showing with 13 additions and 13 deletions.
  1. +4 −4 lib/mac_dns_switcher.coffee
  2. +9 −9 test/mac_dns_switcher_spec.coffee
View
8 lib/mac_dns_switcher.coffee
@@ -12,12 +12,12 @@ module.exports = class MacDnsSwitcher
setDnsServers: (servers) ->
servers = @_buildArgument(servers)
@_run(
- "sudo networksetup -setdnsservers #{@options.network_service} #{servers}")
+ "sudo networksetup -setdnsservers \"#{@options.network_service}\" #{servers}")
setSearchDomains: (domains) ->
domains = @_buildArgument(domains)
@_run(
- "sudo networksetup -setsearchdomains #{@options.network_service} #{domains}")
+ "sudo networksetup -setsearchdomains \"#{@options.network_service}\" #{domains}")
_run: (cmd) ->
output = execSync.stdout(cmd)
@@ -33,9 +33,9 @@ module.exports = class MacDnsSwitcher
getDnsServers: ->
execSync.stdout(
- "networksetup -getdnsservers #{@options.network_service}")
+ "networksetup -getdnsservers \"#{@options.network_service}\"")
getSearchDomains: ->
execSync.stdout(
- "networksetup -getsearchdomains #{@options.network_service}")
+ "networksetup -getsearchdomains \"#{@options.network_service}\"")
View
18 test/mac_dns_switcher_spec.coffee
@@ -11,56 +11,56 @@ MacDnsSwitcher = sandbox.require '../lib/mac_dns_switcher',
describe "MacDnsSwitcher", ->
beforeEach ->
- @switcher = new MacDnsSwitcher(network_service: 'Wi-Fi')
+ @switcher = new MacDnsSwitcher(network_service: 'iPhone USB')
describe "#setDnsServers", ->
describe "for null", ->
it "runs 'sudo networksetup -setdnsservers {network_service} Empty'", ->
@switcher.setDnsServers(null)
- cmd = 'sudo networksetup -setdnsservers Wi-Fi Empty'
+ cmd = 'sudo networksetup -setdnsservers "iPhone USB" Empty'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "for []", ->
it "runs 'sudo networksetup -setdnsservers {network_service} Empty'", ->
@switcher.setDnsServers([])
- cmd = 'sudo networksetup -setdnsservers Wi-Fi Empty'
+ cmd = 'sudo networksetup -setdnsservers "iPhone USB" Empty'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "for ['1.2.3.4', '5.6.7.8']", ->
it "runs 'sudo networksetup -setdnsservers {network_service} {servers}'", ->
@switcher.setDnsServers(['1.2.3.4', '5.6.7.8'])
- cmd = 'sudo networksetup -setdnsservers Wi-Fi 1.2.3.4 5.6.7.8'
+ cmd = 'sudo networksetup -setdnsservers "iPhone USB" 1.2.3.4 5.6.7.8'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "#setSearchDomains", ->
describe "for null", ->
it "runs 'sudo networksetup -setsearchdomains {network_service} Empty'", ->
@switcher.setSearchDomains(null)
- cmd = 'sudo networksetup -setsearchdomains Wi-Fi Empty'
+ cmd = 'sudo networksetup -setsearchdomains "iPhone USB" Empty'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "for []", ->
it "runs 'sudo networksetup -setsearchdomains {network_service} Empty'", ->
@switcher.setSearchDomains([])
- cmd = 'sudo networksetup -setsearchdomains Wi-Fi Empty'
+ cmd = 'sudo networksetup -setsearchdomains "iPhone USB" Empty'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "for ['domain1', 'domain2']", ->
it "runs 'sudo networksetup -setsearchdomains {network_service} {searchdomains}'", ->
@switcher.setSearchDomains(['domain1', 'domain2'])
- cmd = 'sudo networksetup -setsearchdomains Wi-Fi domain1 domain2'
+ cmd = 'sudo networksetup -setsearchdomains "iPhone USB" domain1 domain2'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "#getDnsServers", ->
it "runs 'networksetup -getdnsservers {network_service}'", ->
@switcher.getDnsServers()
- cmd = 'networksetup -getdnsservers Wi-Fi'
+ cmd = 'networksetup -getdnsservers "iPhone USB"'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "#getSearchDomains", ->
it "runs 'networksetup -getsearchdomains {network_service}'", ->
@switcher.getSearchDomains()
- cmd = 'networksetup -getsearchdomains Wi-Fi'
+ cmd = 'networksetup -getsearchdomains "iPhone USB"'
expect(execSync.stdout).to.have.been.calledWith(cmd)
describe "#activate(profile)", ->

0 comments on commit 7b27047

Please sign in to comment.
Something went wrong with that request. Please try again.