Permalink
Browse files

[OHAI-400] fix URI parsing bug when MAC address starts with a number

  • Loading branch information...
1 parent d89cdc0 commit a21fcc7c92fdd8c504adf1566e146d85c411879e @zuazo zuazo committed Dec 12, 2012
Showing with 6 additions and 6 deletions.
  1. +2 −2 lib/ohai/mixin/ec2_metadata.rb
  2. +4 −4 spec/unit/plugins/ec2_spec.rb
@@ -124,8 +124,8 @@ def fetch_userdata()
private
def expand_path(file_name)
- uri = URI.parse(file_name.gsub(/\=.*$/, '/'))
- path = uri.normalize.to_s
+ uri = URI.parse(URI.escape(file_name.gsub(/\=.*$/, '/'), ':'))
+ path = URI.unescape(uri.normalize.to_s)
# ignore "./" and "../"
path.gsub(%r{/\.\.?(?:/|$)}, '/').
sub(%r{^\.\.?(?:/|$)}, '').
@@ -80,17 +80,17 @@
and_return(mock("Net::HTTP Response", :body => "macs/"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/interfaces/macs/").
- and_return(mock("Net::HTTP Response", :body => "fe:ff:ff:ff:ff:ff/"))
+ and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/"))
@http_client.should_receive(:get).
- with("/2012-01-12/meta-data/network/interfaces/macs/fe:ff:ff:ff:ff:ff/").
+ with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/").
and_return(mock("Net::HTTP Response", :body => "public_hostname"))
@http_client.should_receive(:get).
- with("/2012-01-12/meta-data/network/interfaces/macs/fe:ff:ff:ff:ff:ff/public_hostname").
+ with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname").
and_return(mock("Net::HTTP Response", :body => "server17.opscode.com"))
@ohai._require_plugin("ec2")
@ohai[:ec2].should_not be_nil
- @ohai[:ec2]['network_interfaces_macs']['fe:ff:ff:ff:ff:ff']['public_hostname'].should eql('server17.opscode.com')
+ @ohai[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com')
end
it "should parse ec2 iam/ directory and its JSON files properly" do

0 comments on commit a21fcc7

Please sign in to comment.