rack-ketai 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +1 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README.rdoc +122 -0
  4. data/VERSION +1 -0
  5. data/lib/rack/ketai/carrier/abstract.rb +263 -0
  6. data/lib/rack/ketai/carrier/au.rb +153 -0
  7. data/lib/rack/ketai/carrier/cidrs/au.rb +32 -0
  8. data/lib/rack/ketai/carrier/cidrs/docomo.rb +14 -0
  9. data/lib/rack/ketai/carrier/cidrs/softbank.rb +10 -0
  10. data/lib/rack/ketai/carrier/docomo.rb +157 -0
  11. data/lib/rack/ketai/carrier/emoji/ausjisstrtoemojiid.rb +1391 -0
  12. data/lib/rack/ketai/carrier/emoji/docomosjisstrtoemojiid.rb +759 -0
  13. data/lib/rack/ketai/carrier/emoji/emojidata.rb +836 -0
  14. data/lib/rack/ketai/carrier/emoji/emojiidtotypecast.rb +432 -0
  15. data/lib/rack/ketai/carrier/emoji/softbankutf8strtoemojiid.rb +1119 -0
  16. data/lib/rack/ketai/carrier/emoji/softbankwebcodetoutf8str.rb +499 -0
  17. data/lib/rack/ketai/carrier/general.rb +75 -0
  18. data/lib/rack/ketai/carrier/iphone.rb +16 -0
  19. data/lib/rack/ketai/carrier/softbank.rb +144 -0
  20. data/lib/rack/ketai/carrier/specs/au.rb +1 -0
  21. data/lib/rack/ketai/carrier/specs/docomo.rb +1 -0
  22. data/lib/rack/ketai/carrier/specs/softbank.rb +1 -0
  23. data/lib/rack/ketai/carrier.rb +18 -0
  24. data/lib/rack/ketai/display.rb +16 -0
  25. data/lib/rack/ketai/middleware.rb +36 -0
  26. data/lib/rack/ketai.rb +12 -0
  27. data/spec/spec_helper.rb +11 -0
  28. data/spec/unit/au_filter_spec.rb +96 -0
  29. data/spec/unit/au_spec.rb +240 -0
  30. data/spec/unit/carrier_spec.rb +30 -0
  31. data/spec/unit/display_spec.rb +25 -0
  32. data/spec/unit/docomo_filter_spec.rb +106 -0
  33. data/spec/unit/docomo_spec.rb +344 -0
  34. data/spec/unit/emoticon_filter_spec.rb +91 -0
  35. data/spec/unit/filter_spec.rb +38 -0
  36. data/spec/unit/iphone_spec.rb +16 -0
  37. data/spec/unit/middleware_spec.rb +38 -0
  38. data/spec/unit/softbank_filter_spec.rb +133 -0
  39. data/spec/unit/softbank_spec.rb +200 -0
  40. data/spec/unit/valid_addr_spec.rb +86 -0
  41. data/test/spec_runner.rb +29 -0
  42. data/tools/generate_emoji_dic.rb +434 -0
  43. data/tools/update_speclist.rb +87 -0
  44. metadata +138 -0
@@ -0,0 +1,200 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rack/ketai/carrier/softbank'
3
+ describe "Rack::Ketai::Carrier::Softbank" do
4
+
5
+ before(:each) do
6
+
7
+ end
8
+
9
+ # http://creation.mb.softbank.jp/web/web_ua_about.html
10
+ # SoftBank 3G Series => 3GC型
11
+ # C型 P型は省略(もうなくなるし)
12
+
13
+ describe "3GCケータイで" do
14
+
15
+ # http://ke-tai.org/blog/2008/09/08/phoneid/
16
+ # http://creation.mb.softbank.jp/web/web_ua_about.html
17
+
18
+ describe "端末シリアル番号とX-JPHONE-UIDが送信されたとき" do
19
+
20
+ before(:each) do
21
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
22
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1',
23
+ 'HTTP_X_JPHONE_UID' => 'c10Sty5bmqjsZeb2')
24
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
25
+ end
26
+
27
+ it "#subscriberid でx-jphone-uidを取得できること" do
28
+ @mobile.subscriberid.should == 'c10Sty5bmqjsZeb2'
29
+ end
30
+
31
+ it "#deviceid で端末シリアル番号を取得できること" do
32
+ @mobile.deviceid.should == '000000000000000'
33
+ end
34
+
35
+ it "#ident でx-jphone-uidを取得できること" do
36
+ @mobile.ident.should == @mobile.subscriberid
37
+ @mobile.ident.should == 'c10Sty5bmqjsZeb2'
38
+ end
39
+ end
40
+
41
+ describe "端末シリアル番号の送出が禁止されているとき(最近のはデフォルトでこう)" do
42
+
43
+ before(:each) do
44
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
45
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1',
46
+ 'HTTP_X_JPHONE_UID' => 'c10Sty5bmqjsZeb2')
47
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
48
+ end
49
+
50
+ it "#subscriberid でx-jphone-uidを取得できること" do
51
+ @mobile.subscriberid.should == 'c10Sty5bmqjsZeb2'
52
+ end
53
+
54
+ it "#deviceid が nil を返すこと" do
55
+ @mobile.deviceid.should be_nil
56
+ end
57
+
58
+ it "#ident でx-jphone-uidを取得できること" do
59
+ @mobile.ident.should == @mobile.subscriberid
60
+ @mobile.ident.should == 'c10Sty5bmqjsZeb2'
61
+ end
62
+ end
63
+
64
+ describe "X-JPHONE-UIDの送出が禁止されているとき" do
65
+
66
+ before(:each) do
67
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
68
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1')
69
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
70
+ end
71
+
72
+ it "#subscriberid が nil を返すこと" do
73
+ @mobile.subscriberid.should be_nil
74
+ end
75
+
76
+ it "#deviceid で端末シリアル番号を取得できること" do
77
+ @mobile.deviceid.should == '000000000000000'
78
+ end
79
+
80
+ it "#ident で端末シリアル番号を取得できること" do
81
+ @mobile.ident.should == @mobile.deviceid
82
+ @mobile.ident.should == '000000000000000'
83
+ end
84
+ end
85
+
86
+ describe "端末シリアル番号もX-JPHONE-UIDも送出が禁止されているとき" do
87
+
88
+ before(:each) do
89
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
90
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/824T/TJ001 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1')
91
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
92
+ end
93
+
94
+ it "#subscriberid が nil を返すこと" do
95
+ @mobile.subscriberid.should be_nil
96
+ end
97
+
98
+ it "#deviceid が nil を返すこと" do
99
+ @mobile.deviceid.should be_nil
100
+ end
101
+
102
+ it "#ident が nil を返すこと" do
103
+ @mobile.ident.should be_nil
104
+ end
105
+ end
106
+
107
+ describe "ディスプレイ情報を取得できること" do
108
+
109
+ describe "既知の端末のとき" do
110
+
111
+ it "環境変数を優先すること" do
112
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
113
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/933SH/SHJ002[/Serial] Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1',
114
+ 'HTTP_X_JPHONE_DISPLAY' => '1024*768',
115
+ 'HTTP_X_JPHONE_COLOR' => 'C256')
116
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
117
+ display = @mobile.display
118
+ display.should_not be_nil
119
+ display.colors.should == 256
120
+ display.width.should == 1024
121
+ display.height.should == 768
122
+
123
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
124
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/933SH/SHJ002[/Serial] Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1')
125
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
126
+ display = @mobile.display
127
+ display.should_not be_nil
128
+ display.colors.should == 16777216
129
+ display.width.should == 480
130
+ display.height.should == 738
131
+ end
132
+
133
+ end
134
+
135
+ describe "未知の端末のとき" do
136
+
137
+ it "環境変数から設定すること" do
138
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
139
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/100XX/SHJ002[/Serial] Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1',
140
+ 'HTTP_X_JPHONE_DISPLAY' => '1024*768',
141
+ 'HTTP_X_JPHONE_COLOR' => 'C256')
142
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
143
+ display = @mobile.display
144
+ display.should_not be_nil
145
+ display.colors.should == 256
146
+ display.width.should == 1024
147
+ display.height.should == 768
148
+ end
149
+
150
+ it "環境変数が無かったら慌てず騒がず nil を返す" do
151
+ @env = Rack::MockRequest.env_for('http://hoge.com/dummy',
152
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/100XX/SHJ002[/Serial] Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1')
153
+ @mobile = Rack::Ketai::Carrier::Softbank.new(@env)
154
+ display = @mobile.display
155
+ display.should_not be_nil
156
+ display.colors.should be_nil
157
+ display.width.should be_nil
158
+ display.height.should be_nil
159
+ end
160
+
161
+ end
162
+
163
+ end
164
+
165
+ end
166
+
167
+ describe "#cache_size でキャッシュ容量を取得するとき" do
168
+
169
+ it "データにないときは300KBに設定でOK" do
170
+ env = Rack::MockRequest.env_for('http://hoge.com/dummy',
171
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/923SH/SHJ001/SN*************** Browser/NetFront/3.4 Profile/MIDP-2.0 Configuration/CLDC-1.1')
172
+ mobile = Rack::Ketai::Carrier::Softbank.new(env)
173
+ mobile.name.should == '923SH'
174
+ mobile.cache_size.should == 300000
175
+ end
176
+
177
+ it "仕方ないので、データにあればそれを信用" do
178
+ env = Rack::MockRequest.env_for('http://hoge.com/dummy',
179
+ 'HTTP_USER_AGENT' => 'SoftBank/2.0/944SH/SHJ001/SN*************** Browser/NetFront/3.5 Profile/MIDP-2.0 Configuration/CLDC-1.1')
180
+ mobile = Rack::Ketai::Carrier::Softbank.new(env)
181
+ mobile.name.should == '944SH'
182
+ mobile.cache_size.should == 500000
183
+ end
184
+
185
+ end
186
+
187
+ describe "#supports_cookie? を使うとき" do
188
+ # Softbank のCookie対応状況
189
+ # W型、3GC型機種のみ対応…C型、P型もサービス終了につき、
190
+ # 現状はすべて対応のはず
191
+ it "#supports_cookie? は true を返す" do
192
+ env = Rack::MockRequest.env_for('http://hoge.com/dummy',
193
+ 'HTTP_USER_AGENT' => 'SoftBank/1.0/930SH/SHJ001[/Serial] Browser/NetFront/3.4 Profile/MIDP-2.0 Configuration/CLDC-1.1')
194
+ mobile = Rack::Ketai::Carrier::Softbank.new(env)
195
+ mobile.should be_respond_to(:supports_cookie?)
196
+ mobile.should be_supports_cookie
197
+ end
198
+ end
199
+
200
+ end
@@ -0,0 +1,86 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rack/ketai/carrier/docomo'
3
+ describe "Rack::Ketai::Carrier::*.valid_addr? を使うとき" do
4
+
5
+ def from(carrier, addr)
6
+ env = Rack::MockRequest.env_for('http://hoge.com/dummy',
7
+ 'HTTP_USER_AGENT' => 'DoCoMo/1.0/N505i/c20/TB/W24H12',
8
+ 'HTTP_X_DCMGUID' => '0123abC',
9
+ 'REMOTE_ADDR' => addr)
10
+ carrier.new(env)
11
+ end
12
+
13
+ CIDRS = {
14
+ :Docomo => %w(
15
+ 210.153.84.0/24
16
+ 210.136.161.0/24
17
+ 210.153.86.0/24
18
+ 124.146.174.0/24
19
+ 124.146.175.0/24
20
+ 202.229.176.0/24
21
+ 202.229.177.0/24
22
+ 202.229.178.0/24
23
+ ),
24
+ :Au => %w(
25
+ 210.230.128.224/28
26
+ 121.111.227.160/27
27
+ 61.117.1.0/28
28
+ 219.108.158.0/27
29
+ 219.125.146.0/28
30
+ 61.117.2.32/29
31
+ 61.117.2.40/29
32
+ 219.108.158.40/29
33
+ 219.125.148.0/25
34
+ 222.5.63.0/25
35
+ 222.5.63.128/25
36
+ 222.5.62.128/25
37
+ 59.135.38.128/25
38
+ 219.108.157.0/25
39
+ 219.125.145.0/25
40
+ 121.111.231.0/25
41
+ 121.111.227.0/25
42
+ 118.152.214.192/26
43
+ 118.159.131.0/25
44
+ 118.159.133.0/25
45
+ 118.159.132.160/27
46
+ 111.86.142.0/26
47
+ 111.86.141.64/26
48
+ 111.86.141.128/26
49
+ 111.86.141.192/26
50
+ ),
51
+ :Softbank => %w(
52
+ 123.108.237.0/27
53
+ 202.253.96.224/27
54
+ 210.146.7.192/26
55
+ 210.175.1.128/25
56
+ )
57
+ }.freeze
58
+
59
+ it "キャリア指定のアドレス帯域からのアクセスであれば真を返すこと" do
60
+ CIDRS.each do |carrier_name, cidrs|
61
+ klass = Rack::Ketai::Carrier.const_get(carrier_name)
62
+ cidrs.each do |cidr|
63
+ addrs = IPAddr.new(cidr).to_range.to_a
64
+ from(klass, addrs.first.to_s).should be_valid_addr
65
+ from(klass, addrs[(addrs.size - 1)/2].to_s).should be_valid_addr
66
+ from(klass, addrs.last.to_s).should be_valid_addr
67
+ end
68
+ end
69
+ end
70
+
71
+ it "キャリア指定のアドレス帯域からのアクセスでなければ偽を返すこと" do
72
+ CIDRS.each do |carrier_name, cidrs|
73
+ ([Rack::Ketai::Carrier::Docomo,
74
+ Rack::Ketai::Carrier::Au,
75
+ Rack::Ketai::Carrier::Softbank] - [Rack::Ketai::Carrier.const_get(carrier_name)]).each do |klass|
76
+ cidrs.each do |cidr|
77
+ addrs = IPAddr.new(cidr).to_range.to_a
78
+ from(klass, addrs.first.to_s).should_not be_valid_addr
79
+ from(klass, addrs[(addrs.size - 1)/2].to_s).should_not be_valid_addr
80
+ from(klass, addrs.last.to_s).should_not be_valid_addr
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ end
@@ -0,0 +1,29 @@
1
+ require 'test/unit'
2
+
3
+ class SpecRunner < Test::Unit::TestCase
4
+
5
+ def load_spec
6
+ begin
7
+ require 'spec'
8
+ rescue LoadError
9
+ retry if require "rubygems"
10
+ puts "All tests are skipped."
11
+ return
12
+ end
13
+ end
14
+
15
+ def test_spec
16
+ return unless load_spec
17
+ require File.join(File.dirname(__FILE__),
18
+ '../spec/spec_helper.rb')
19
+
20
+ argv = Dir.glob(File.join(File.dirname(__FILE__),
21
+ '../spec/**/*_spec.rb'))
22
+ argv.unshift '-fs'
23
+
24
+ unless Spec::Runner::CommandLine.run(Spec::Runner::OptionParser.parse(argv, STDOUT, STDERR))
25
+ fail "failure(s)."
26
+ end
27
+ end
28
+
29
+ end