summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2014-04-25 12:15:37 +0200
committerazul <azul@riseup.net>2014-04-25 12:15:37 +0200
commit76ad25ba0ee344f185f8e8cdfe066685cd3b0447 (patch)
treed8122b5b5144c917f5e1924c1428a3a871e94149 /test
parent2b6200f508ddb8e1c8a76fd3778881c39d787d8d (diff)
parentbe81b7430e0a2046125be7c3a4b01b8725f4afe6 (diff)
Merge pull request #148 from azul/feature/api-quota-support
Feature/api quota support + current_user null pattern
Diffstat (limited to 'test')
-rw-r--r--test/functional/v1/certs_controller_test.rb46
-rw-r--r--test/functional/v1/services_controller_test.rb31
-rw-r--r--test/unit/anonymous_user_test.rb23
-rw-r--r--test/unit/unauthenticated_user_test.rb7
4 files changed, 78 insertions, 29 deletions
diff --git a/test/functional/v1/certs_controller_test.rb b/test/functional/v1/certs_controller_test.rb
index 2c70e52..fb8e9c4 100644
--- a/test/functional/v1/certs_controller_test.rb
+++ b/test/functional/v1/certs_controller_test.rb
@@ -2,43 +2,45 @@ require 'test_helper'
class V1::CertsControllerTest < ActionController::TestCase
- test "send limited cert without login" do
- with_config allow_limited_certs: true, allow_anonymous_certs: true do
- cert = stub :to_s => "limited cert"
- ClientCertificate.expects(:new).with(:prefix => APP_CONFIG[:limited_cert_prefix]).returns(cert)
+ test "send unlimited cert without login" do
+ with_config allow_anonymous_certs: true do
+ cert = expect_cert('UNLIMITED')
get :show
assert_response :success
assert_equal cert.to_s, @response.body
end
end
- test "send unlimited cert" do
- with_config allow_unlimited_certs: true do
+ test "send limited cert" do
+ with_config allow_limited_certs: true do
login
- cert = stub :to_s => "unlimited cert"
- ClientCertificate.expects(:new).with(:prefix => APP_CONFIG[:unlimited_cert_prefix]).returns(cert)
+ cert = expect_cert('LIMITED')
get :show
assert_response :success
assert_equal cert.to_s, @response.body
end
end
- test "login required if anonymous certs disabled" do
- with_config allow_anonymous_certs: false do
- get :show
- assert_response :redirect
- end
+ test "send unlimited cert" do
+ login effective_service_level: ServiceLevel.new(id: 2)
+ cert = expect_cert('UNLIMITED')
+ get :show
+ assert_response :success
+ assert_equal cert.to_s, @response.body
end
- test "send limited cert" do
- with_config allow_limited_certs: true, allow_unlimited_certs: false do
- login
- cert = stub :to_s => "real cert"
- ClientCertificate.expects(:new).with(:prefix => APP_CONFIG[:limited_cert_prefix]).returns(cert)
- get :show
- assert_response :success
- assert_equal cert.to_s, @response.body
- end
+ test "redirect if no eip service offered" do
+ get :show
+ assert_response :redirect
end
+ protected
+
+ def expect_cert(prefix)
+ cert = stub :to_s => "#{prefix.downcase} cert"
+ ClientCertificate.expects(:new).
+ with(:prefix => prefix).
+ returns(cert)
+ return cert
+ end
end
diff --git a/test/functional/v1/services_controller_test.rb b/test/functional/v1/services_controller_test.rb
new file mode 100644
index 0000000..e4058c0
--- /dev/null
+++ b/test/functional/v1/services_controller_test.rb
@@ -0,0 +1,31 @@
+require 'test_helper'
+
+class V1::ServicesControllerTest < ActionController::TestCase
+
+ test "anonymous user gets login required service info" do
+ get :show, format: :json
+ assert_json_response name: 'anonymous',
+ eip_rate_limit: false,
+ description: 'please login to access our services'
+ end
+
+ test "anonymous user gets vpn service info" do
+ with_config allow_anonymous_certs: true do
+ get :show, format: :json
+ assert_json_response name: 'anonymous',
+ eip_rate_limit: false,
+ description: 'anonymous access to the VPN'
+ end
+ end
+
+ test "user can see their service info" do
+ login
+ get :show, format: :json
+ assert_json_response name: 'free',
+ eip_rate_limit: true,
+ description: 'free account, with rate limited VPN',
+ storage: 100
+ end
+
+end
+
diff --git a/test/unit/anonymous_user_test.rb b/test/unit/anonymous_user_test.rb
new file mode 100644
index 0000000..6e94d39
--- /dev/null
+++ b/test/unit/anonymous_user_test.rb
@@ -0,0 +1,23 @@
+require 'test_helper'
+
+class AnonymousUserTest < ActiveSupport::TestCase
+
+ setup do
+ @anonymous = AnonymousUser.new
+ end
+
+ test "has nil values" do
+ assert_nil @anonymous.id
+ assert_nil @anonymous.email_address
+ assert_nil @anonymous.login
+ end
+
+ test "has no messages" do
+ assert_equal [], @anonymous.messages
+ end
+
+ test "has anonymous service level" do
+ assert @anonymous.effective_service_level.is_a? AnonymousServiceLevel
+ end
+
+end
diff --git a/test/unit/unauthenticated_user_test.rb b/test/unit/unauthenticated_user_test.rb
deleted file mode 100644
index e5fafb8..0000000
--- a/test/unit/unauthenticated_user_test.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require 'test_helper'
-
-class UnauthenticatedUserTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
-end