Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for WEP connections to the settings hash

  • Loading branch information...
commit 53a806101eb0c228ed9dc80a5cab91d295e97071 1 parent bc9284a
Steven Steffen authored February 15, 2012
15  lib/network_manager/settings_hash.rb
... ...
@@ -1,7 +1,7 @@
1 1
 class NetworkManager::SettingsHash < Hash
2 2
 
3 3
   # Generates a connection settings hash for a wifi connection.
4  
-  def self.create_wifi_settings(ssid, pass = nil)
  4
+  def self.create_wifi_settings(ssid, pass = nil, wpa_flags = 0)
5 5
     connection_settings = {
6 6
       'id' => ssid,
7 7
       'uuid' => ActiveSupport::SecureRandom.uuid,
@@ -21,10 +21,19 @@ def self.create_wifi_settings(ssid, pass = nil)
21 21
     if security
22 22
       wifi_settings["security"] = security
23 23
       security_settings = {
24  
-        'key-mgmt' => 'wpa-psk',
25  
-        'psk' => pass,
26 24
         'name' => '802-11-wireless-security'
27 25
       }
  26
+      if(wpa_flags != 0)
  27
+        security_settings.merge!({
  28
+          'key-mgmt' => 'wpa-psk',
  29
+          'psk' => pass
  30
+        })
  31
+      else
  32
+        security_settings.merge!({
  33
+          'key-mgmt' => 'none',
  34
+          'wep-key0' => pass
  35
+        })
  36
+      end
28 37
     end
29 38
     ipv4_settings = {
30 39
       'method' => 'auto',
15  spec/lib/network_manager/settings_hash_spec.rb
@@ -8,7 +8,7 @@
8 8
   describe :create_wifi_settings do
9 9
     context "should give settings for Test AP with password pass with string ssid" do
10 10
       before(:each) do
11  
-        @hash = NetworkManager::SettingsHash.create_wifi_settings("Test", "pass")
  11
+        @hash = NetworkManager::SettingsHash.create_wifi_settings("Test", "pass", 325)
12 12
       end
13 13
       specify {@hash.should be_a Hash}
14 14
       specify {@hash['connection']['type'].should eql '802-11-wireless'}
@@ -18,7 +18,7 @@
18 18
 
19 19
     context "should give settings for Test AP with password pass with byte array ssid" do
20 20
       before(:each) do
21  
-        @hash = NetworkManager::SettingsHash.create_wifi_settings("Test", "pass")
  21
+        @hash = NetworkManager::SettingsHash.create_wifi_settings("Test", "pass", 1)
22 22
       end
23 23
       specify {@hash.should be_a Hash}
24 24
       specify {@hash['connection']['type'].should eql '802-11-wireless'}
@@ -34,6 +34,17 @@
34 34
       specify {@hash['connection']['type'].should eql '802-11-wireless'}
35 35
       specify {@hash['802-11-wireless-security'].should eql nil}
36 36
     end
  37
+
  38
+    context "should give settings for Test AP a WEP connection with password" do
  39
+      before(:each) do
  40
+        @hash = NetworkManager::SettingsHash.create_wifi_settings("Test", "pass", 0)
  41
+      end
  42
+      specify{@hash.should be_a Hash}
  43
+      specify {@hash['connection']['type'].should eql '802-11-wireless'}
  44
+      specify {@hash['802-11-wireless']['ssid'][1].should eql([84, 101, 115, 116])}
  45
+      specify {@hash['802-11-wireless-security']['key-mgmt'].should eql 'none'}
  46
+      specify {@hash['802-11-wireless-security']['wep-key0'].should eql("pass")}
  47
+    end
37 48
   end
38 49
 
39 50
   describe :create_ethernet_settings do

0 notes on commit 53a8061

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