Commit 0d2ac9fb4bdec670be8be3d6c15531e1a2e10af3
1 parent
a590ddfe
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Added initial tests
Showing
1 changed file
with
51 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,51 @@ |
| 1 | +require File.dirname(__FILE__) + '/test_helper' | |
| 2 | + | |
| 3 | +class LoginCaptchaTest < ActiveSupport::TestCase | |
| 4 | + | |
| 5 | + url = "/api/v1/login-captcha?" | |
| 6 | + | |
| 7 | + def setup() | |
| 8 | + environment = Environment.default | |
| 9 | + environment.api_captcha_settings = { | |
| 10 | + enabled: true, | |
| 11 | + provider: 'serpro', | |
| 12 | + serpro_client_id: '0000000000000000', | |
| 13 | + verify_uri: 'http://captcha.serpro.gov.br/validate', | |
| 14 | + } | |
| 15 | + environment.save! | |
| 16 | + | |
| 17 | + end | |
| 18 | + | |
| 19 | + should 'not generate private token when login without captcha' do | |
| 20 | + params = {} | |
| 21 | + post "#{url}#{params.to_query}" | |
| 22 | + json = JSON.parse(last_response.body) | |
| 23 | + puts "JSon1: #{json}" | |
| 24 | + assert json["private_token"].blank? | |
| 25 | + end | |
| 26 | + | |
| 27 | + should 'generate private token when login with captcha' do | |
| 28 | + #request = mock() | |
| 29 | + stub_request(:post, "http://captcha.serpro.gov.br/validate"). | |
| 30 | + with(:body => "0000000000000000&4324343&4030320", | |
| 31 | + :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). | |
| 32 | + to_return(:status => 200, :body => "1", :headers => {}) | |
| 33 | + | |
| 34 | + # Mock the user to check the private_token | |
| 35 | + token = "private_token@1234" | |
| 36 | + user = mock | |
| 37 | + User.expects(:new).returns(user) | |
| 38 | + user.expects(:generate_private_token!).returns(token) | |
| 39 | + # To store the user session helpers.rb call the private_token method | |
| 40 | + user.expects(:private_token).times(2).returns(token) | |
| 41 | + | |
| 42 | + params = {:txtToken_captcha_serpro_gov_br => '4324343', :captcha_text => '4030320'} | |
| 43 | + post "#{url}#{params.to_query}" | |
| 44 | + json = JSON.parse(last_response.body) | |
| 45 | + puts "JSon2: #{json}" | |
| 46 | + assert !json["private_token"].blank? | |
| 47 | + ret = json["private_token"] | |
| 48 | + assert ret == token | |
| 49 | + end | |
| 50 | + | |
| 51 | +end | |
| 0 | 52 | \ No newline at end of file | ... | ... |