uuidtools 2.1.3 → 2.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ == UUIDTools 2.1.4
2
+ * various OS-specific improvements to obtaining MAC address
3
+ == UUIDTools 2.1.3
4
+ * changes to build system
5
+ == UUIDTools 2.1.2
6
+ * fixed issue with frozen objects
7
+ * fixed issue with running specs in Ruby 1.9.2
1
8
  == UUIDTools 2.1.1
2
9
  * fixed issue with Ruby 1.9 compatibility
3
10
  == UUIDTools 2.1.0
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ PKG_FILES = FileList[
24
24
  "lib/**/*", "spec/**/*", "vendor/**/*",
25
25
  "tasks/**/*", "website/**/*",
26
26
  "[A-Z]*", "Rakefile"
27
- ].exclude(/database\.yml/).exclude(/[_\.]git$/)
27
+ ].exclude(/database\.yml/).exclude(/[_\.]git$/).exclude(/Gemfile/).exclude(/Gemfile\.lock/)
28
28
 
29
29
  task :default => "spec"
30
30
 
@@ -426,19 +426,21 @@ module UUIDTools
426
426
  ##
427
427
  # Returns the hex digest of the UUID object.
428
428
  def hexdigest
429
- self.frozen? ? generate_hexdigest : (@hexdigest ||= generate_hexdigest)
429
+ (self.frozen? ?
430
+ generate_hexdigest : (@hexdigest ||= generate_hexdigest)
431
+ ).dup
430
432
  end
431
433
 
432
434
  ##
433
435
  # Returns the raw bytes that represent this UUID.
434
436
  def raw
435
- self.frozen? ? generate_raw : (@raw ||= generate_raw)
437
+ (self.frozen? ? generate_raw : (@raw ||= generate_raw)).dup
436
438
  end
437
439
 
438
440
  ##
439
441
  # Returns a string representation for this UUID.
440
442
  def to_s
441
- self.frozen? ? generate_s : (@string ||= generate_s)
443
+ (self.frozen? ? generate_s : (@string ||= generate_s)).dup
442
444
  end
443
445
  alias_method :to_str, :to_s
444
446
 
@@ -520,116 +522,114 @@ module UUIDTools
520
522
  return self == other
521
523
  end
522
524
 
525
+ #
526
+ # Determine what OS we're running on. Helps decide how to find the MAC
527
+ #
528
+ def self.os_class
529
+ require 'rbconfig'
530
+ os_platform = RbConfig::CONFIG['target_os']
531
+ os_class = nil
532
+ if (os_platform =~ /win/i && !(os_platform =~ /darwin/i)) ||
533
+ os_platform =~ /w32/i
534
+ os_class = :windows
535
+ elsif os_platform =~ /solaris/i
536
+ os_class = :solaris
537
+ elsif os_platform =~ /netbsd/i
538
+ os_class = :netbsd
539
+ elsif os_platform =~ /openbsd/i
540
+ os_class = :openbsd
541
+ end
542
+ end
543
+
544
+ # making these class variables helps with testing
545
+ @ifconfig_command = "ifconfig"
546
+ @ifconfig_path_default = "/sbin/ifconfig"
547
+ @ip_command = "ip"
548
+ @ip_path_default = "/sbin/ip"
549
+
550
+ class << self
551
+ attr_accessor :ifconfig_command, :ifconfig_path_default
552
+ attr_accessor :ip_command, :ip_path_default
553
+ end
554
+
555
+ #
556
+ # Find the path of the ifconfig(8) command if it is present
557
+ #
558
+ def self.ifconfig_path
559
+ path = `which #{UUID.ifconfig_command} 2>/dev/null`.strip
560
+ path = UUID.ifconfig_path_default if (path == "" && File.exist?(UUID.ifconfig_path_default))
561
+ return (path === "" ? nil : path)
562
+ end
563
+
564
+ #
565
+ # Find the path of the ip(8) command if it is present
566
+ #
567
+ def self.ip_path
568
+ path = `which #{UUID.ip_command} 2>/dev/null`.strip
569
+ path = UUID.ip_path_default if (path == "" && File.exist?(UUID.ip_path_default))
570
+ return (path === "" ? nil : path)
571
+ end
572
+
573
+ #
574
+ # Call the ifconfig or ip command that is found
575
+ #
576
+ def self.ifconfig(all=nil)
577
+ # find the path of the ifconfig command
578
+ ifconfig_path = UUID.ifconfig_path
579
+
580
+ # if it does not exist, try the ip command
581
+ if ifconfig_path == nil
582
+ ifconfig_path = UUID.ip_path
583
+ # all makes no sense when using ip(1)
584
+ all = nil
585
+ end
586
+
587
+ all_switch = all == nil ? "" : "-a"
588
+ return `#{ifconfig_path} #{all_switch}` if not ifconfig_path == nil
589
+ end
590
+
591
+ # Match and return the first Mac address found
592
+ def self.first_mac(instring)
593
+ mac_regexps = [
594
+ Regexp.new("address:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
595
+ Regexp.new("addr:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
596
+ Regexp.new("ether:? (#{(["[0-9a-fA-F]{1,2}"] * 6).join(":")})"),
597
+ Regexp.new("HWaddr:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
598
+ Regexp.new("link/ether? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
599
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
600
+ Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})")
601
+ ]
602
+ parse_mac = lambda do |output|
603
+ (mac_regexps.map do |regexp|
604
+ result = output[regexp, 1]
605
+ result.downcase.gsub(/-/, ":") if result != nil
606
+ end).compact.first
607
+ end
608
+
609
+ mac = parse_mac.call(instring)
610
+ # expand octets that were compressed (solaris)
611
+ mac.split(':').map { |c| (c.length == 1 ? "0#{c}" : c)}.join(':')
612
+
613
+ end
614
+
523
615
  ##
524
616
  # Returns the MAC address of the current computer's network card.
525
617
  # Returns nil if a MAC address could not be found.
526
618
  def self.mac_address
527
619
  if !defined?(@@mac_address)
528
620
  require 'rbconfig'
529
- os_platform = RbConfig::CONFIG['target_os']
530
- os_class = nil
531
- if (os_platform =~ /win/i && !(os_platform =~ /darwin/i)) ||
532
- os_platform =~ /w32/i
533
- os_class = :windows
534
- elsif os_platform =~ /solaris/i
535
- os_class = :solaris
536
- elsif os_platform =~ /netbsd/i
537
- os_class = :netbsd
538
- elsif os_platform =~ /openbsd/i
539
- os_class = :openbsd
540
- end
541
- mac_regexps = [
542
- Regexp.new("address:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
543
- Regexp.new("addr:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
544
- Regexp.new("ether:? (#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
545
- Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join(":")})"),
546
- Regexp.new("(#{(["[0-9a-fA-F]{2}"] * 6).join("-")})")
547
- ]
548
- parse_mac = lambda do |output|
549
- (mac_regexps.map do |regexp|
550
- result = output[regexp, 1]
551
- result.downcase.gsub(/-/, ":") if result != nil
552
- end).compact.first
553
- end
621
+
622
+ os_class = UUID.os_class
623
+
554
624
  if os_class == :windows
555
- script_in_path = true
556
- else
557
- script_in_path = Kernel.system("which ifconfig 2>&1 > /dev/null")
558
- end
559
- if os_class == :solaris
560
625
  begin
561
- ifconfig_output =
562
- (script_in_path ? `ifconfig -a` : `/sbin/ifconfig -a`)
563
- ip_addresses = ifconfig_output.scan(
564
- /inet\s?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
565
- ip = ip_addresses.find {|addr| addr[0] != '127.0.0.1'}[0]
566
- @@mac_address = `/usr/sbin/arp #{ip}`.split(' ')[3]
567
- rescue Exception
568
- end
569
- if @@mac_address == "" || @@mac_address == nil
570
- begin
571
- ifconfig_output =
572
- (script_in_path ?
573
- `ifconfig -a` : `/sbin/ifconfig -a`).split(' ')
574
- index = ifconfig_output.index("inet") + 1
575
- ip = ifconfig_output[index]
576
- @@mac_address = `arp #{ip}`.split(' ')[3]
577
- rescue Exception
578
- end
579
- end
580
- elsif os_class == :windows
581
- begin
582
- @@mac_address = parse_mac.call(`ipconfig /all`)
583
- rescue
584
- end
585
- else
586
- begin
587
- if os_class == :netbsd
588
- @@mac_address = parse_mac.call(
589
- script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
590
- )
591
- elsif os_class == :openbsd
592
- @@mac_address = parse_mac.call(
593
- script_in_path ? `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
594
- )
595
- elsif File.exists?('/sbin/ifconfig')
596
- @@mac_address = parse_mac.call(
597
- script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`
598
- )
599
- if @@mac_address == nil
600
- @@mac_address = parse_mac.call(
601
- script_in_path ?
602
- `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
603
- )
604
- end
605
- if @@mac_address == nil
606
- @@mac_address = parse_mac.call(
607
- script_in_path ?
608
- `ifconfig | grep HWaddr | cut -c39- 2>&1` :
609
- `/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`
610
- )
611
- end
612
- else
613
- @@mac_address = parse_mac.call(
614
- script_in_path ? `ifconfig 2>&1` : `/sbin/ifconfig 2>&1`
615
- )
616
- if @@mac_address == nil
617
- @@mac_address = parse_mac.call(
618
- script_in_path ?
619
- `ifconfig -a 2>&1` : `/sbin/ifconfig -a 2>&1`
620
- )
621
- end
622
- if @@mac_address == nil
623
- @@mac_address = parse_mac.call(
624
- script_in_path ?
625
- `ifconfig | grep HWaddr | cut -c39- 2>&1` :
626
- `/sbin/ifconfig | grep HWaddr | cut -c39- 2>&1`
627
- )
628
- end
629
- end
626
+ @@mac_address = UUID.first_mac `ipconfig /all`
630
627
  rescue
631
628
  end
629
+ else # linux, bsd, macos, solaris
630
+ @@mac_address = UUID.first_mac(UUID.ifconfig(:all))
632
631
  end
632
+
633
633
  if @@mac_address != nil
634
634
  if @@mac_address.respond_to?(:to_str)
635
635
  @@mac_address = @@mac_address.to_str
@@ -22,7 +22,7 @@ unless defined? UUIDTools::VERSION
22
22
  module VERSION #:nodoc:
23
23
  MAJOR = 2
24
24
  MINOR = 1
25
- TINY = 3
25
+ TINY = 4
26
26
 
27
27
  STRING = [MAJOR, MINOR, TINY].join('.')
28
28
  end
@@ -1,15 +1,459 @@
1
1
  require File.expand_path("../../spec_helper.rb", __FILE__)
2
2
 
3
+ def pending_if_root_required
4
+ if @mac_address == nil
5
+ output = `ifconfig -a 2>&1`
6
+ if output =~ /inet/ &&
7
+ output =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ &&
8
+ output =~ /Warning: cannot open/
9
+ pending("Cannot get MAC address without root?")
10
+ end
11
+ end
12
+ end
13
+
14
+ # ===========================================================================
15
+ #
16
+ # Samples of ifconfig -a output
17
+ #
18
+ # ===========================================================================
19
+
20
+ #
21
+ # solaris
22
+ #
23
+ solaris_sample = <<EOF
24
+ lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
25
+ inet 127.0.0.1 netmask ff000000
26
+ igb1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
27
+ inet 10.51.0.18 netmask ffffff00 broadcast 10.51.0.255
28
+ ether 0:21:28:fa:c6:65
29
+ igb2: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
30
+ inet 10.99.0.12 netmask ffffff00 broadcast 10.99.0.255
31
+ ether 0:21:28:fa:c6:66
32
+ EOF
33
+
34
+ solaris_mac = "00:21:28:fa:c6:65"
35
+
36
+ #
37
+ # windows
38
+ #
39
+ windows_sample = <<EOF
40
+ Windows IP Configuration
41
+
42
+ Host Name . . . . . . . . . . . . : OFFICE
43
+ Primary Dns Suffix . . . . . . . :
44
+ Node Type . . . . . . . . . . . . : Unknown
45
+ IP Routing Enabled. . . . . . . . : No
46
+ WINS Proxy Enabled. . . . . . . . : No
47
+
48
+ Ethernet adapter Local Area Connection:
49
+
50
+ Connection-specific DNS Suffix . :
51
+ Description . . . . . . . . . . . : Realtek PCIe GBE Family Controller
52
+ Physical Address. . . . . . . . . : E0-CB-4E-5D-BC-E9
53
+ Dhcp Enabled. . . . . . . . . . . : No
54
+ IP Address. . . . . . . . . . . . : 192.168.1.10
55
+ Subnet Mask . . . . . . . . . . . : 255.255.255.0
56
+ Default Gateway . . . . . . . . . : 192.168.1.1
57
+ DNS Servers . . . . . . . . . . . : 192.168.1.1
58
+ 4.2.2.1
59
+ EOF
60
+
61
+ windows_mac = "e0:cb:4e:5d:bc:e9"
62
+
63
+ #
64
+ # linux
65
+ #
66
+ linux_sample = <<EOF
67
+ eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
68
+ inet 10.16.187.71 netmask 255.255.252.0 broadcast 10.16.187.255
69
+ inet6 fe80::226:2dff:fef6:b94 prefixlen 64 scopeid 0x20<link>
70
+ ether 00:26:2d:f6:0b:94 txqueuelen 1000 (Ethernet)
71
+ RX packets 172074 bytes 82784684 (78.9 MiB)
72
+ RX errors 0 dropped 0 overruns 0 frame 0
73
+ TX packets 99075 bytes 23551085 (22.4 MiB)
74
+ TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
75
+ device interrupt 20 memory 0xf2600000-f2620000
76
+
77
+ lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
78
+ inet 127.0.0.1 netmask 255.0.0.0
79
+ inet6 ::1 prefixlen 128 scopeid 0x10<host>
80
+ loop txqueuelen 0 (Local Loopback)
81
+ RX packets 20 bytes 2148 (2.0 KiB)
82
+ RX errors 0 dropped 0 overruns 0 frame 0
83
+ TX packets 20 bytes 2148 (2.0 KiB)
84
+ TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
85
+ EOF
86
+
87
+ linux_mac = "00:26:2d:f6:0b:94"
88
+
89
+ #
90
+ # alternate linux
91
+ #
92
+ linux_sample_2 = <<EOF
93
+ eth0 Link encap:Ethernet HWaddr 00:80:C8:F8:4A:51
94
+ inet addr:192.168.99.35 Bcast:192.168.99.255 Mask:255.255.255.0
95
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
96
+ RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
97
+ TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
98
+ collisions:0 txqueuelen:100
99
+ RX bytes:30701229 (29.2 Mb) TX bytes:7878951 (7.5 Mb)
100
+ Interrupt:9 Base address:0x5000
101
+
102
+ lo Link encap:Local Loopback
103
+ inet addr:127.0.0.1 Mask:255.0.0.0
104
+ UP LOOPBACK RUNNING MTU:16436 Metric:1
105
+ RX packets:306 errors:0 dropped:0 overruns:0 frame:0
106
+ TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
107
+ collisions:0 txqueuelen:0
108
+ RX bytes:29504 (28.8 Kb) TX bytes:29504 (28.8 Kb)
109
+ EOF
110
+
111
+ linux_mac_2 = "00:80:c8:f8:4a:51"
112
+
113
+ linux_ip_sample = <<EOF
114
+ 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
115
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
116
+ inet 127.0.0.1/8 scope host lo
117
+ inet6 ::1/128 scope host
118
+ valid_lft forever preferred_lft forever
119
+ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
120
+ link/ether 00:26:2d:f6:0b:94 brd ff:ff:ff:ff:ff:ff
121
+ inet 10.16.187.125/22 brd 10.16.187.255 scope global eth0
122
+ inet6 fe80::226:2dff:fef6:b94/64 scope link
123
+ valid_lft forever preferred_lft forever
124
+ 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000
125
+ link/ether 00:26:c6:c6:1a:b4 brd ff:ff:ff:ff:ff:ff
126
+ 4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
127
+ link/ether 52:54:00:e3:cf:d3 brd ff:ff:ff:ff:ff:ff
128
+ inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
129
+ 5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
130
+ link/ether 52:54:00:e3:cf:d3 brd ff:ff:ff:ff:ff:ff
131
+ EOF
132
+
133
+ linux_ip_mac = "00:26:2d:f6:0b:94"
134
+
135
+ #
136
+ # freebsd
137
+ #
138
+ freebsd_sample = <<EOF
139
+ igb0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
140
+ options=401bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,VLAN_HWTSO>
141
+ ether 00:25:90:2b:81:32
142
+ inet6 fe80::225:90ff:fe2b:8132%igb0 prefixlen 64 scopeid 0x1
143
+ nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
144
+ media: Ethernet autoselect (1000baseT <full-duplex>)
145
+ status: active
146
+ igb1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
147
+ options=401bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,VLAN_HWTSO>
148
+ ether 00:25:90:2b:81:32
149
+ inet6 fe80::225:90ff:fe2b:8133%igb1 prefixlen 64 scopeid 0x2
150
+ nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
151
+ media: Ethernet autoselect (1000baseT <full-duplex>)
152
+ EOF
153
+
154
+ freebsd_mac = "00:25:90:2b:81:32"
155
+
156
+ #
157
+ # openbsd
158
+ #
159
+ openbsd_sample = <<EOF
160
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200
161
+ priority: 0
162
+ groups: lo
163
+ inet 127.0.0.1 netmask 0xff000000
164
+ inet6 ::1 prefixlen 128
165
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
166
+ vr0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
167
+ lladdr 00:0d:b9:28:ab:44
168
+ priority: 0
169
+ media: Ethernet autoselect (100baseTX full-duplex)
170
+ status: active
171
+ inet 192.168.7.2 netmask 0xffffff00 broadcast 192.168.7.255
172
+ inet6 fe80::20d:b9ff:fe28:ab44%vr0 prefixlen 64 scopeid 0x1
173
+ EOF
174
+
175
+ openbsd_mac = "00:0d:b9:28:ab:44"
176
+
177
+ #
178
+ # MacOS 10
179
+ #
180
+ macos_sample = <<EOF
181
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
182
+ options=3<RXCSUM,TXCSUM>
183
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
184
+ inet 127.0.0.1 netmask 0xff000000
185
+ inet6 ::1 prefixlen 128
186
+ gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
187
+ stf0: flags=0<> mtu 1280
188
+ en0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
189
+ options=27<RXCSUM,TXCSUM,VLAN_MTU,TSO4>
190
+ ether 58:b0:35:a4:cd:0c
191
+ inet6 fe80::5ab0:35ff:fea4:cd0c%en0 prefixlen 64 scopeid 0x4
192
+ inet 192.168.142.136 netmask 0xfffffff0 broadcast 192.168.142.143
193
+ media: autoselect (1000baseT <full-duplex,flow-control>)
194
+ status: active
195
+ en1: flags=8823<UP,BROADCAST,SMART,SIMPLEX,MULTICAST> mtu 1500
196
+ ether d8:30:62:51:dd:3d
197
+ media: autoselect (<unknown type>)
198
+ status: inactive
199
+ p2p0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 2304
200
+ ether 0a:30:62:51:dd:3d
201
+ media: autoselect
202
+ status: inactive
203
+ EOF
204
+
205
+ macos_mac = "58:b0:35:a4:cd:0c"
206
+
207
+ # Gather the samples and MAC addresses for simple access
208
+ samples = {
209
+ :macos => macos_sample,
210
+ :windows => windows_sample,
211
+ :solaris => solaris_sample,
212
+ :freebsd => freebsd_sample,
213
+ :openbsd => openbsd_sample,
214
+ :linux => linux_sample,
215
+ :linux2 => linux_sample_2,
216
+ :linuxip => linux_ip_sample
217
+ }
218
+
219
+ macs = {
220
+ :macos => macos_mac,
221
+ :windows => windows_mac,
222
+ :solaris => solaris_mac,
223
+ :freebsd => freebsd_mac,
224
+ :openbsd => openbsd_mac,
225
+ :linux => linux_mac,
226
+ :linux2 => linux_mac_2,
227
+ :linuxip => linux_ip_mac
228
+ }
229
+
230
+ # --------------------------------------------------------------------------
231
+ #
232
+ # TESTS
233
+ #
234
+ # --------------------------------------------------------------------------
235
+
3
236
  describe UUIDTools::UUID, "when obtaining a MAC address" do
4
237
  before do
5
238
  @mac_address = UUIDTools::UUID.mac_address
6
239
  end
7
240
 
8
241
  it "should obtain a MAC address" do
242
+ pending_if_root_required()
9
243
  @mac_address.should_not be_nil
10
244
  end
11
245
 
12
246
  it "should cache the MAC address" do
247
+ pending_if_root_required()
13
248
  @mac_address.object_id.should == UUIDTools::UUID.mac_address.object_id
14
249
  end
250
+
251
+ end
252
+
253
+ describe UUIDTools::UUID, "before obtaining a MAC address" do
254
+
255
+ before do
256
+ module UUIDTools
257
+ class UUID
258
+ remove_class_variable(:@@mac_address) if defined?(@@mac_address)
259
+ end
260
+ end
261
+ end
262
+
263
+ it "should parse windows MAC addresses" do
264
+ # mock ifconfig() to return the windows sample
265
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:windows])
266
+ mac = UUIDTools::UUID.mac_address
267
+ mac.should be == macs[:windows]
268
+ end
269
+
270
+ it "should parse solaris MAC addresses" do
271
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:solaris])
272
+ mac = UUIDTools::UUID.mac_address
273
+ mac.should be == macs[:solaris]
274
+ end
275
+
276
+ it "should parse freebsd MAC addresses" do
277
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:freebsd])
278
+ mac = UUIDTools::UUID.mac_address
279
+ mac.should be == macs[:freebsd]
280
+ end
281
+
282
+ it "should parse openbsd MAC addresses" do
283
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:openbsd])
284
+ mac = UUIDTools::UUID.mac_address
285
+ mac.should be == macs[:openbsd]
286
+ end
287
+
288
+ it "should parse linux MAC addresses with ifconfig" do
289
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:linux])
290
+ mac = UUIDTools::UUID.mac_address
291
+ mac.should be == macs[:linux]
292
+ end
293
+
294
+ it "should parse a linux HWaddr address with ifconfig" do
295
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:linux2])
296
+ mac = UUIDTools::UUID.mac_address
297
+ mac.should be == macs[:linux2]
298
+ end
299
+
300
+ it "should parse macos MAC addresses with ifconfig" do
301
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:macos])
302
+ mac = UUIDTools::UUID.mac_address
303
+ mac.should be == macs[:macos]
304
+ end
305
+
306
+ it "should parse linux MAC addresses with ip" do
307
+ UUIDTools::UUID.stub(:ifconfig).and_return(samples[:linuxip])
308
+ mac = UUIDTools::UUID.mac_address
309
+ mac.should be == macs[:linuxip]
310
+ end
311
+
312
+ it "should identify the default os classes" do
313
+ module RbConfig
314
+ CONFIG['target_os'] = nil
315
+ end
316
+
317
+ os_class = UUIDTools::UUID.os_class
318
+ os_class.should be == nil
319
+
320
+ RbConfig::CONFIG['target_os'] = 'linux'
321
+ os_class = UUIDTools::UUID.os_class
322
+ os_class.should be == nil
323
+
324
+ RbConfig::CONFIG['target_os'] = 'darwin'
325
+ os_class = UUIDTools::UUID.os_class
326
+ os_class.should be == nil
327
+ end
328
+
329
+ it "should identify the solaris os classes" do
330
+ module RbConfig
331
+ CONFIG['target_os'] = "solaris"
332
+ end
333
+
334
+ os_class = UUIDTools::UUID.os_class
335
+ os_class.should be == :solaris
336
+ end
337
+
338
+ it "should identify the BSD os classes" do
339
+ module RbConfig
340
+ CONFIG['target_os'] = "netbsd"
341
+ end
342
+
343
+ os_class = UUIDTools::UUID.os_class
344
+ os_class.should be == :netbsd
345
+
346
+ RbConfig::CONFIG['target_os'] = "openbsd"
347
+ os_class = UUIDTools::UUID.os_class
348
+ os_class.should be == :openbsd
349
+
350
+ end
351
+
352
+ it "should identify the Windows os classes" do
353
+ module RbConfig
354
+ CONFIG['target_os'] = "win"
355
+ end
356
+ os_class = UUIDTools::UUID.os_class
357
+ os_class.should be == :windows
358
+
359
+ RbConfig::CONFIG['target_os'] = "w32"
360
+ os_class = UUIDTools::UUID.os_class
361
+ os_class.should be == :windows
362
+
363
+ RbConfig::CONFIG['target_os'] = "darwin"
364
+ os_class = UUIDTools::UUID.os_class
365
+ os_class.should be == nil
366
+
367
+ end
368
+
369
+ it "should find the ifconfig program" do
370
+ save_ifconfig_command = UUIDTools::UUID.ifconfig_command
371
+ save_ifconfig_path = UUIDTools::UUID.ifconfig_path_default
372
+
373
+ # this should always exist
374
+ UUIDTools::UUID.ifconfig_command="sh"
375
+ UUIDTools::UUID.ifconfig_path_default="notfound"
376
+ ifconfig_path = UUIDTools::UUID.ifconfig_path
377
+ # ifconfig_path.should be == "/usr/bin/sh"
378
+
379
+ # Test what happens if it does not
380
+ UUIDTools::UUID.ifconfig_command="nosuchthing"
381
+ UUIDTools::UUID.ifconfig_path_default="default"
382
+
383
+ # ifconfig_path checks if the IFCONFIG_PATH command file exists
384
+ File.stub(:exist?).and_return(true)
385
+
386
+ ifconfig_path = UUIDTools::UUID.ifconfig_path
387
+ # ifconfig_path.should be == "default"
388
+
389
+ UUIDTools::UUID.ifconfig_command=save_ifconfig_command
390
+ UUIDTools::UUID.ifconfig_path_default=save_ifconfig_path
391
+
392
+ end
393
+
394
+ it "should find the ip program" do
395
+ save_ip_command = UUIDTools::UUID.ip_command
396
+ save_ip_path = UUIDTools::UUID.ip_path_default
397
+
398
+ # this should always exist
399
+ UUIDTools::UUID.ip_command="sh"
400
+ UUIDTools::UUID.ip_path_default="notfound"
401
+ ip_path = UUIDTools::UUID.ip_path
402
+ # ip_path.should be == "/usr/bin/sh"
403
+
404
+ # Test what happens if it does not
405
+ UUIDTools::UUID.ip_command="nosuchthing"
406
+ UUIDTools::UUID.ip_path_default="default"
407
+
408
+ # ifconfig_path checks if the IP_PATH command file exists
409
+ File.stub(:exist?).and_return(true)
410
+
411
+ ifconfig_path = UUIDTools::UUID.ip_path
412
+ # ifconfig_path.should be == "default"
413
+
414
+ UUIDTools::UUID.ip_command=save_ip_command
415
+ UUIDTools::UUID.ip_path_default=save_ip_path
416
+ end
417
+
418
+ it "should return the output of the ifconfig program" do
419
+ pending "I'm not quite sure how to mock backticks"
420
+ end
421
+
422
+ it "should be able to parse windows ipconfig output" do
423
+ mac = UUIDTools::UUID.first_mac samples[:windows]
424
+ mac.should be == macs[:windows]
425
+ end
426
+
427
+ it "should be able to parse solaris ifconfig output" do
428
+ mac = UUIDTools::UUID.first_mac samples[:solaris]
429
+ mac.should be == macs[:solaris]
430
+ end
431
+
432
+ it "should be able to parse freebsd ifconfig output" do
433
+ mac = UUIDTools::UUID.first_mac samples[:freebsd]
434
+ mac.should be == macs[:freebsd]
435
+ end
436
+
437
+ it "should be able to parse openbsd ifconfig output" do
438
+ mac = UUIDTools::UUID.first_mac samples[:openbsd]
439
+ mac.should be == macs[:openbsd]
440
+ end
441
+
442
+ it "should be able to parse linux ifconfig output" do
443
+ mac = UUIDTools::UUID.first_mac samples[:linux]
444
+ mac.should be == macs[:linux]
445
+
446
+ mac2 = UUIDTools::UUID.first_mac samples[:linux2]
447
+ mac2.should be == macs[:linux2]
448
+ end
449
+
450
+ it "should be able to parse macos ifconfig output" do
451
+ mac = UUIDTools::UUID.first_mac samples[:macos]
452
+ mac.should be == macs[:macos]
453
+ end
454
+
455
+ it "should be able to parse ip addr output" do
456
+ mac = UUIDTools::UUID.first_mac samples[:linuxip]
457
+ mac.should be == macs[:linuxip]
458
+ end
15
459
  end
@@ -44,6 +44,13 @@ describe UUIDTools::UUID, "when generating" do
44
44
  (uuids.map {|x| x.to_s}).uniq.size.should == uuids.size
45
45
  end
46
46
 
47
+ it "should not have internal state used in string representations" do
48
+ uuid = UUIDTools::UUID.random_create
49
+ uuid_string = uuid.to_s.dup
50
+ uuid.to_s.gsub!("-", "/")
51
+ uuid.to_s.should == uuid_string
52
+ end
53
+
47
54
  it "should throw an exception if a segment has an invalid value" do
48
55
  (lambda do
49
56
  UUIDTools::UUID.new(-1, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
metadata CHANGED
@@ -1,75 +1,92 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: uuidtools
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.4
4
5
  prerelease:
5
- version: 2.1.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Bob Aman
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-07-16 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-04-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.7.3
24
22
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
30
25
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.3
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
34
37
  version: 2.9.0
35
38
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: yard
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
45
53
  version: 0.8.2
46
54
  type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: launchy
50
55
  prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: launchy
64
+ requirement: !ruby/object:Gem::Requirement
52
65
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
56
69
  version: 2.0.0
57
70
  type: :development
58
- version_requirements: *id004
59
- description: |
60
- A simple universally unique ID generation library.
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.0.0
78
+ description: ! 'A simple universally unique ID generation library.
61
79
 
80
+ '
62
81
  email: bob@sporkmonger.com
63
82
  executables: []
64
-
65
83
  extensions: []
66
-
67
- extra_rdoc_files:
84
+ extra_rdoc_files:
68
85
  - README.md
69
- files:
86
+ files:
70
87
  - lib/compat/securerandom.rb
71
- - lib/uuidtools/version.rb
72
88
  - lib/uuidtools.rb
89
+ - lib/uuidtools/version.rb
73
90
  - spec/spec.opts
74
91
  - spec/spec_helper.rb
75
92
  - spec/uuidtools/mac_address_spec.rb
@@ -85,38 +102,33 @@ files:
85
102
  - tasks/yard.rake
86
103
  - website/index.html
87
104
  - CHANGELOG
88
- - Gemfile
89
- - Gemfile.lock
90
105
  - LICENSE.txt
91
- - Rakefile
92
106
  - README.md
107
+ - Rakefile
93
108
  homepage: http://uuidtools.rubyforge.org/
94
109
  licenses: []
95
-
96
110
  post_install_message:
97
- rdoc_options:
111
+ rdoc_options:
98
112
  - --main
99
113
  - README.md
100
- require_paths:
114
+ require_paths:
101
115
  - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
116
+ required_ruby_version: !ruby/object:Gem::Requirement
103
117
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- version: "0"
108
- required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  none: false
110
- requirements:
111
- - - ">="
112
- - !ruby/object:Gem::Version
113
- version: "0"
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
114
128
  requirements: []
115
-
116
129
  rubyforge_project:
117
130
  rubygems_version: 1.8.24
118
131
  signing_key:
119
132
  specification_version: 3
120
133
  summary: UUID generator
121
134
  test_files: []
122
-
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group :development do
4
- gem 'launchy', '>= 2.0.0'
5
- gem 'yard', '>= 0.8.2'
6
- gem 'redcarpet'
7
- gem 'rubyforge'
8
- end
9
-
10
- group :test, :development do
11
- gem 'rake', '>= 0.7.3'
12
- gem 'rspec', '>= 2.9.0'
13
- end
14
-
15
- gemspec
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- uuidtools (2.1.1)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- addressable (2.2.8)
10
- diff-lcs (1.1.3)
11
- json_pure (1.7.3)
12
- launchy (2.1.0)
13
- addressable (~> 2.2.6)
14
- rake (0.9.2.2)
15
- redcarpet (2.1.1)
16
- rspec (2.11.0)
17
- rspec-core (~> 2.11.0)
18
- rspec-expectations (~> 2.11.0)
19
- rspec-mocks (~> 2.11.0)
20
- rspec-core (2.11.0)
21
- rspec-expectations (2.11.1)
22
- diff-lcs (~> 1.1.3)
23
- rspec-mocks (2.11.1)
24
- rubyforge (2.0.4)
25
- json_pure (>= 1.1.7)
26
- yard (0.8.2.1)
27
-
28
- PLATFORMS
29
- ruby
30
-
31
- DEPENDENCIES
32
- launchy (>= 2.0.0)
33
- rake (>= 0.7.3)
34
- redcarpet
35
- rspec (>= 2.9.0)
36
- rubyforge
37
- uuidtools!
38
- yard