Commit 4aceccc6428101afa7d97c37511b92056c18d1b0
1 parent
87b669b8
Exists in
captcha_serpro_plugin
Separation from plugin
Showing
16 changed files
with
0 additions
and
832 deletions
Show diff stats
plugins/serpro_captcha/Gemfile
... | ... | @@ -1 +0,0 @@ |
1 | -gem 'webmock' |
plugins/serpro_captcha/README.md
plugins/serpro_captcha/controllers/serpro_captcha_plugin_admin_controller.rb
... | ... | @@ -1,17 +0,0 @@ |
1 | -class SerproCaptchaPluginAdminController < PluginAdminController | |
2 | - | |
3 | - append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
4 | - | |
5 | - def index | |
6 | - end | |
7 | - | |
8 | - def update | |
9 | - if @environment.update_attributes(params[:environment]) | |
10 | - session[:notice] = _('Captcha configuration updated successfully.') | |
11 | - else | |
12 | - session[:notice] = _('Captcha configuration could not be saved.') | |
13 | - end | |
14 | - render :action => 'index' | |
15 | - end | |
16 | - | |
17 | -end |
plugins/serpro_captcha/fixtures/ldap.yml.dist
... | ... | @@ -1,15 +0,0 @@ |
1 | -server: | |
2 | - host: "127.0.0.1" | |
3 | - port: 389 | |
4 | - account: "uid=ldap_user,,ou=person,dc=noosfero,dc=org" | |
5 | - account_password: "ldap_pass" | |
6 | - base_dn: "dc=noosfero,dc=org" | |
7 | - attr_login: "uid" | |
8 | - attr_fullname: "cn" | |
9 | - attr_mail: "mail" | |
10 | - onthefly_register: true | |
11 | - filter: "" | |
12 | - tls: false | |
13 | -user: | |
14 | - login: 'valid_ldap_login' | |
15 | - password: 'valid_ldap_password' |
plugins/serpro_captcha/lib/ext/environment.rb
... | ... | @@ -1,35 +0,0 @@ |
1 | -require_dependency 'environment' | |
2 | - | |
3 | -class Environment | |
4 | - | |
5 | - #Captcha settings | |
6 | - settings_items :serpro_captcha_plugin, :type => ActiveSupport::HashWithIndifferentAccess, :default => {} | |
7 | - | |
8 | -# settings_items :verify_uri, :type => :string, :default => 'http://captcha.servicoscorporativos.serpro.gov.br/captchavalidar/1.0.0/validar' | |
9 | -# settings_items :serpro_client_id, :type => :string, :default => 'fdbcdc7a0b754ee7ae9d865fda740f17' | |
10 | - | |
11 | - attr_accessible :serpro_captcha_plugin_attributes, :serpro_captcha_verify_uri, :serpro_captcha_client_id | |
12 | - | |
13 | - def serpro_captcha_plugin_attributes | |
14 | - self.serpro_captcha_plugin || {} | |
15 | - end | |
16 | - | |
17 | - def serpro_captcha_verify_uri= verify_uri | |
18 | - self.serpro_captcha_plugin = {} if self.serpro_captcha_plugin.blank? | |
19 | - self.serpro_captcha_plugin['serpro_captcha_verify_uri'] = verify_uri | |
20 | - end | |
21 | - | |
22 | - def serpro_captcha_verify_uri | |
23 | - self.serpro_captcha_plugin['serpro_captcha_verify_uri'] | |
24 | - end | |
25 | - | |
26 | - def serpro_captcha_client_id= client_id | |
27 | - self.serpro_captcha_plugin = {} if self.serpro_captcha_plugin.blank? | |
28 | - self.serpro_captcha_plugin['serpro_captcha_client_id'] = client_id | |
29 | - end | |
30 | - | |
31 | - def serpro_captcha_client_id | |
32 | - self.serpro_captcha_plugin['serpro_captcha_client_id'] | |
33 | - end | |
34 | - | |
35 | -end |
plugins/serpro_captcha/lib/serpro_captcha_plugin.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -class SerproCaptchaPlugin < Noosfero::Plugin | |
2 | - | |
3 | - def self.plugin_name | |
4 | - _('Serpro\'s captcha plugin') | |
5 | - end | |
6 | - | |
7 | - def self.plugin_description | |
8 | - _("Provides a plugin to Serpro's captcha infrastructure.") | |
9 | - end | |
10 | - | |
11 | - def self.api_mount_points | |
12 | - [SerproCaptchaPlugin::API ] | |
13 | - end | |
14 | - | |
15 | - def test_captcha(remote_ip, params, environment) | |
16 | - scv = SerproCaptchaVerification.new | |
17 | - return scv.verify_serpro_captcha(environment.serpro_captcha_client_id, params[:txtToken_captcha_serpro_gov_br], params[:captcha_text], environment.serpro_captcha_verify_uri) | |
18 | - end | |
19 | - | |
20 | -end |
plugins/serpro_captcha/lib/serpro_captcha_verification.rb
... | ... | @@ -1,31 +0,0 @@ |
1 | -class SerproCaptchaVerification | |
2 | - | |
3 | - # return true or a hash with the error | |
4 | - # :user_message, :status, :log_message, :javascript_console_message | |
5 | - def verify_serpro_captcha(client_id, token, captcha_text, verify_uri) | |
6 | - msg_icve = _('Internal captcha validation error') | |
7 | - msg_esca = 'Environment serpro_captcha_plugin_attributes' | |
8 | - return hash_error(msg_icve, 500, nil, "#{msg_esca} verify_uri not defined") if verify_uri.nil? | |
9 | - return hash_error(msg_icve, 500, nil, "#{msg_esca} client_id not defined") if client_id.nil? | |
10 | - return hash_error(_("Error processing token validation"), 500, nil, _("Missing Serpro's Captcha token")) unless token | |
11 | - return hash_error(_('Captcha text has not been filled'), 403) unless captcha_text | |
12 | - uri = URI(verify_uri) | |
13 | - http = Net::HTTP.new(uri.host, uri.port) | |
14 | - request = Net::HTTP::Post.new(uri.path) | |
15 | - verify_string = "#{client_id}&#{token}&#{captcha_text}" | |
16 | - request.body = verify_string | |
17 | - body = http.request(request).body | |
18 | - return true if body == '1' | |
19 | - return hash_error(_("Internal captcha validation error"), 500, body, "Unable to reach Serpro's Captcha validation service") if body == "Activity timed out" | |
20 | - return hash_error(_("Wrong captcha text, please try again"), 403) if body == '0' | |
21 | - return hash_error(_("Serpro's captcha token not found"), 500) if body == '2' | |
22 | - return hash_error(_("No data sent to validation server or other serious problem"), 500) if body == -1 | |
23 | - #Catches all errors at the end | |
24 | - return hash_error(_("Internal captcha validation error"), 500, nil, "Error validating Serpro's captcha service returned: #{body}") | |
25 | - end | |
26 | - | |
27 | - def hash_error(user_message, status, log_message=nil, javascript_console_message=nil) | |
28 | - {user_message: user_message, status: status, log_message: log_message, javascript_console_message: javascript_console_message} | |
29 | - end | |
30 | - | |
31 | -end |
plugins/serpro_captcha/po/de/ldap.po
... | ... | @@ -1,99 +0,0 @@ |
1 | -# German translation of noosfero. | |
2 | -# Copyright (C) 2009-2013 Josef Spillner | |
3 | -# Copyright (C) 2009, 2011 Ronny Kursawe | |
4 | -# This file is distributed under the same license as the noosfero package. | |
5 | -# Josef Spillner <josef.spillner@tu-dresden.de>, 2009. | |
6 | -# | |
7 | -msgid "" | |
8 | -msgstr "" | |
9 | -"Project-Id-Version: 1.2~rc2-23-g29aba34\n" | |
10 | -"POT-Creation-Date: 2015-08-06 18:47-0300\n" | |
11 | -"PO-Revision-Date: 2014-12-12 14:23+0200\n" | |
12 | -"Last-Translator: Michal Čihař <michal@cihar.com>\n" | |
13 | -"Language-Team: German <https://hosted.weblate.org/projects/noosfero/noosfero/" | |
14 | -"de/>\n" | |
15 | -"Language: de\n" | |
16 | -"MIME-Version: 1.0\n" | |
17 | -"Content-Type: text/plain; charset=UTF-8\n" | |
18 | -"Content-Transfer-Encoding: 8bit\n" | |
19 | -"Plural-Forms: nplurals=2; plural=n != 1;\n" | |
20 | -"X-Generator: Weblate 2.2-dev\n" | |
21 | - | |
22 | -#: plugins/ldap/lib/serpro_captcha_plugin.rb:11 | |
23 | -#, fuzzy | |
24 | -msgid "A plugin that add ldap support." | |
25 | -msgstr "Ein Plugin, welches dies und jenes tut." | |
26 | - | |
27 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:10 | |
28 | -#, fuzzy | |
29 | -msgid "Ldap configuration updated successfully." | |
30 | -msgstr "Optionen erfolgreich aktualisiert." | |
31 | - | |
32 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:12 | |
33 | -#, fuzzy | |
34 | -msgid "Ldap configuration could not be saved." | |
35 | -msgstr "Die Konfiguration konnte nicht gespeichert werden" | |
36 | - | |
37 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:1 | |
38 | -#, fuzzy | |
39 | -msgid "Ldap Management" | |
40 | -msgstr "Inhalt verwalten" | |
41 | - | |
42 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:8 | |
43 | -msgid "Value" | |
44 | -msgstr "Wert" | |
45 | - | |
46 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:11 | |
47 | -msgid "Host" | |
48 | -msgstr "Rechner" | |
49 | - | |
50 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:15 | |
51 | -msgid "Port" | |
52 | -msgstr "" | |
53 | - | |
54 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:19 | |
55 | -#, fuzzy | |
56 | -msgid "Account" | |
57 | -msgstr "Preisermäßigung" | |
58 | - | |
59 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:23 | |
60 | -#, fuzzy | |
61 | -msgid "Account Password" | |
62 | -msgstr "Derzeitiges Passwort" | |
63 | - | |
64 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:27 | |
65 | -msgid "Base DN" | |
66 | -msgstr "" | |
67 | - | |
68 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:31 | |
69 | -#, fuzzy | |
70 | -msgid "LDAP Filter" | |
71 | -msgstr "Filter" | |
72 | - | |
73 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:35 | |
74 | -#, fuzzy | |
75 | -msgid "On the fly creation" | |
76 | -msgstr "Im letzten Monat" | |
77 | - | |
78 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:39 | |
79 | -msgid "LDAPS" | |
80 | -msgstr "" | |
81 | - | |
82 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:46 | |
83 | -msgid "Attributes" | |
84 | -msgstr "" | |
85 | - | |
86 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:53 | |
87 | -#, fuzzy | |
88 | -msgid "Fullname" | |
89 | -msgstr "Vollständiger Name" | |
90 | - | |
91 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:57 | |
92 | -#, fuzzy | |
93 | -msgid "Mail" | |
94 | -msgstr "E-Mail" | |
95 | - | |
96 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:65 | |
97 | -#, fuzzy | |
98 | -msgid "Back to plugins administration panel" | |
99 | -msgstr "Zurück zum Adminfeld" |
plugins/serpro_captcha/po/ldap.pot
... | ... | @@ -1,86 +0,0 @@ |
1 | -# SOME DESCRIPTIVE TITLE. | |
2 | -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER | |
3 | -# This file is distributed under the same license as the PACKAGE package. | |
4 | -# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | |
5 | -# | |
6 | -#, fuzzy | |
7 | -msgid "" | |
8 | -msgstr "" | |
9 | -"Project-Id-Version: 1.2~rc2-23-g29aba34\n" | |
10 | -"POT-Creation-Date: 2015-08-06 18:47-0300\n" | |
11 | -"PO-Revision-Date: 2015-08-06 17:21-0300\n" | |
12 | -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | |
13 | -"Language-Team: LANGUAGE <LL@li.org>\n" | |
14 | -"Language: \n" | |
15 | -"MIME-Version: 1.0\n" | |
16 | -"Content-Type: text/plain; charset=UTF-8\n" | |
17 | -"Content-Transfer-Encoding: 8bit\n" | |
18 | -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" | |
19 | - | |
20 | -#: plugins/ldap/lib/serpro_captcha_plugin.rb:11 | |
21 | -msgid "A plugin that add ldap support." | |
22 | -msgstr "" | |
23 | - | |
24 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:10 | |
25 | -msgid "Ldap configuration updated successfully." | |
26 | -msgstr "" | |
27 | - | |
28 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:12 | |
29 | -msgid "Ldap configuration could not be saved." | |
30 | -msgstr "" | |
31 | - | |
32 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:1 | |
33 | -msgid "Ldap Management" | |
34 | -msgstr "" | |
35 | - | |
36 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:8 | |
37 | -msgid "Value" | |
38 | -msgstr "" | |
39 | - | |
40 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:11 | |
41 | -msgid "Host" | |
42 | -msgstr "" | |
43 | - | |
44 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:15 | |
45 | -msgid "Port" | |
46 | -msgstr "" | |
47 | - | |
48 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:19 | |
49 | -msgid "Account" | |
50 | -msgstr "" | |
51 | - | |
52 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:23 | |
53 | -msgid "Account Password" | |
54 | -msgstr "" | |
55 | - | |
56 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:27 | |
57 | -msgid "Base DN" | |
58 | -msgstr "" | |
59 | - | |
60 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:31 | |
61 | -msgid "LDAP Filter" | |
62 | -msgstr "" | |
63 | - | |
64 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:35 | |
65 | -msgid "On the fly creation" | |
66 | -msgstr "" | |
67 | - | |
68 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:39 | |
69 | -msgid "LDAPS" | |
70 | -msgstr "" | |
71 | - | |
72 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:46 | |
73 | -msgid "Attributes" | |
74 | -msgstr "" | |
75 | - | |
76 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:53 | |
77 | -msgid "Fullname" | |
78 | -msgstr "" | |
79 | - | |
80 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:57 | |
81 | -msgid "Mail" | |
82 | -msgstr "" | |
83 | - | |
84 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:65 | |
85 | -msgid "Back to plugins administration panel" | |
86 | -msgstr "" |
plugins/serpro_captcha/po/pt/ldap.po
... | ... | @@ -1,93 +0,0 @@ |
1 | -# translation of noosfero.po to | |
2 | -# Krishnamurti Lelis Lima Vieira Nunes <krishna@colivre.coop.br>, 2007. | |
3 | -# noosfero - Brazilian Portuguese translation | |
4 | -# Copyright (C) 2007, | |
5 | -# Forum Brasileiro de Economia Solidaria <http://www.fbes.org.br/> | |
6 | -# Copyright (C) 2007, | |
7 | -# Ynternet.org Foundation <http://www.ynternet.org/> | |
8 | -# This file is distributed under the same license as noosfero itself. | |
9 | -# Joenio Costa <joenio@colivre.coop.br>, 2008. | |
10 | -# | |
11 | -# | |
12 | -msgid "" | |
13 | -msgstr "" | |
14 | -"Project-Id-Version: 1.2~rc2-23-g29aba34\n" | |
15 | -"POT-Creation-Date: 2015-08-06 18:47-0300\n" | |
16 | -"PO-Revision-Date: 2014-12-18 18:40-0200\n" | |
17 | -"Last-Translator: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>\n" | |
18 | -"Language-Team: Portuguese <https://hosted.weblate.org/projects/noosfero/" | |
19 | -"noosfero/pt/>\n" | |
20 | -"Language: pt\n" | |
21 | -"MIME-Version: 1.0\n" | |
22 | -"Content-Type: text/plain; charset=UTF-8\n" | |
23 | -"Content-Transfer-Encoding: 8bit\n" | |
24 | -"Plural-Forms: nplurals=2; plural=n != 1;\n" | |
25 | -"X-Generator: Weblate 2.0\n" | |
26 | - | |
27 | -#: plugins/ldap/lib/serpro_captcha_plugin.rb:11 | |
28 | -msgid "A plugin that add ldap support." | |
29 | -msgstr "Um plugin que adiciona suporte a ldap." | |
30 | - | |
31 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:10 | |
32 | -msgid "Ldap configuration updated successfully." | |
33 | -msgstr "Configuração do Ldap atualizada com sucesso." | |
34 | - | |
35 | -#: plugins/ldap/controllers/serpro_captcha_plugin_admin_controller.rb:12 | |
36 | -msgid "Ldap configuration could not be saved." | |
37 | -msgstr "Configuração do Ldap não pode ser salva." | |
38 | - | |
39 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:1 | |
40 | -msgid "Ldap Management" | |
41 | -msgstr "Gerenciamento do Ldap" | |
42 | - | |
43 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:8 | |
44 | -msgid "Value" | |
45 | -msgstr "Valor" | |
46 | - | |
47 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:11 | |
48 | -msgid "Host" | |
49 | -msgstr "Host" | |
50 | - | |
51 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:15 | |
52 | -msgid "Port" | |
53 | -msgstr "Porta" | |
54 | - | |
55 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:19 | |
56 | -msgid "Account" | |
57 | -msgstr "Conta" | |
58 | - | |
59 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:23 | |
60 | -msgid "Account Password" | |
61 | -msgstr "Senha da conta" | |
62 | - | |
63 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:27 | |
64 | -msgid "Base DN" | |
65 | -msgstr "DN Base" | |
66 | - | |
67 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:31 | |
68 | -msgid "LDAP Filter" | |
69 | -msgstr "Filtro LDAP" | |
70 | - | |
71 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:35 | |
72 | -msgid "On the fly creation" | |
73 | -msgstr "Criação sob-demanda" | |
74 | - | |
75 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:39 | |
76 | -msgid "LDAPS" | |
77 | -msgstr "LDAPS" | |
78 | - | |
79 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:46 | |
80 | -msgid "Attributes" | |
81 | -msgstr "Atributos" | |
82 | - | |
83 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:53 | |
84 | -msgid "Fullname" | |
85 | -msgstr "Nome completo" | |
86 | - | |
87 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:57 | |
88 | -msgid "Mail" | |
89 | -msgstr "Mail" | |
90 | - | |
91 | -#: plugins/ldap/views/serpro_captcha_plugin_admin/index.html.erb:65 | |
92 | -msgid "Back to plugins administration panel" | |
93 | -msgstr "Voltar ao painel de administração" |
plugins/serpro_captcha/test/functional/account_controller_plugin_test.rb
... | ... | @@ -1,18 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | - | |
3 | -# Re-raise errors caught by the controller. | |
4 | -class AccountController; def rescue_action(e) raise e end; end | |
5 | - | |
6 | -class AccountControllerPluginTest < ActionController::TestCase | |
7 | - | |
8 | - def setup | |
9 | - @controller = AccountController.new | |
10 | - @request = ActionController::TestRequest.new | |
11 | - @response = ActionController::TestResponse.new | |
12 | - | |
13 | - @environment = Environment.default | |
14 | - @environment.enabled_plugins = ['SerproCaptchaPlugin'] | |
15 | - @environment.save! | |
16 | - end | |
17 | - | |
18 | -end |
plugins/serpro_captcha/test/functional/serpro_captcha_test.rb
... | ... | @@ -1,29 +0,0 @@ |
1 | -# require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | -# require File.dirname(__FILE__) + '/../../controllers/serpro_captcha_plugin_admin_controller' | |
3 | -# | |
4 | -# # Re-raise errors caught by the controller. | |
5 | -# class SerproCaptchaPluginAdminController; def rescue_action(e) raise e end; end | |
6 | -# | |
7 | -# class SerproCaptchaPluginAdminControllerTest < ActionController::TestCase | |
8 | -# | |
9 | -# def setup | |
10 | -# @environment = Environment.default | |
11 | -# user_login = create_admin_user(@environment) | |
12 | -# login_as(user_login) | |
13 | -# @admin = User[user_login].person | |
14 | -# @environment.enabled_plugins = ['SerproCaptchaPlugin'] | |
15 | -# @environment.serpro_captcha_plugin_host="http://somehost" | |
16 | -# @environment.save! | |
17 | -# end | |
18 | -# | |
19 | -# should 'detected error, Name or service not known, for Serpro captcha communication' do | |
20 | -# environment = Environment.default | |
21 | -# environment.serpro_captcha_verify_uri = 'http://someserverthatdoesnotexist.mycompanythatdoesnotexist.com/validate' | |
22 | -# environment.serpro_captcha_client_id = '000000000000' | |
23 | -# environment.save! | |
24 | -# params = {:login => "newuserapi", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com", | |
25 | -# :txtToken_captcha_serpro_gov_br => '4324343', :captcha_text => '4030320'} | |
26 | -# post "/api/v1/register?#{params.to_query}" | |
27 | -# message = JSON.parse(last_response.body)['javascript_console_message'] | |
28 | -# assert_equal "Serpro captcha error: getaddrinfo: Name or service not known", message | |
29 | -# end |
plugins/serpro_captcha/test/test_helper.rb
... | ... | @@ -1,65 +0,0 @@ |
1 | -require "#{Rails.root}/lib/noosfero/api/helpers" | |
2 | - | |
3 | -class ActiveSupport::TestCase | |
4 | - | |
5 | - include Rack::Test::Methods | |
6 | - | |
7 | - def app | |
8 | - Noosfero::API::API | |
9 | - end | |
10 | - | |
11 | - def pass_captcha(mocked_url, captcha_verification_body) | |
12 | - stub_request(:post, mocked_url). | |
13 | - with(:body => captcha_verification_body, | |
14 | - :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). | |
15 | - to_return(:status => 200, :body => "1", :headers => {'Content-Length' => 1}) | |
16 | - end | |
17 | - | |
18 | - def fail_captcha_text(mocked_url, captcha_verification_body) | |
19 | - stub_request(:post, mocked_url). | |
20 | - with(:body => captcha_verification_body, | |
21 | - :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}). | |
22 | - to_return(:status => 200, :body => "0", :headers => {'Content-Length' => 1}) | |
23 | - end | |
24 | - | |
25 | - def login_with_captcha | |
26 | - json = do_login_captcha_from_api | |
27 | - @private_token = json["private_token"] | |
28 | - @params = { "private_token" => @private_token} | |
29 | - json | |
30 | - end | |
31 | - | |
32 | - ## Performs a login using the session.rb but mocking the | |
33 | - ## real HTTP request to validate the captcha. | |
34 | - def do_login_captcha_from_api | |
35 | - post "/api/v1/login-captcha" | |
36 | - json = JSON.parse(last_response.body) | |
37 | - json | |
38 | - end | |
39 | - | |
40 | - def login_api | |
41 | - @environment = Environment.default | |
42 | - @user = User.create!(:login => 'testapi', :password => 'testapi', :password_confirmation => 'testapi', :email => 'test@test.org', :environment => @environment) | |
43 | - @user.activate | |
44 | - @person = @user.person | |
45 | - | |
46 | - post "/api/v1/login?login=testapi&password=testapi" | |
47 | - json = JSON.parse(last_response.body) | |
48 | - @private_token = json["private_token"] | |
49 | - unless @private_token | |
50 | - @user.generate_private_token! | |
51 | - @private_token = @user.private_token | |
52 | - end | |
53 | - | |
54 | - @params = {:private_token => @private_token} | |
55 | - end | |
56 | - attr_accessor :private_token, :user, :person, :params, :environment | |
57 | - | |
58 | - private | |
59 | - | |
60 | - def json_response_ids(kind) | |
61 | - json = JSON.parse(last_response.body) | |
62 | - json[kind.to_s].map {|c| c['id']} | |
63 | - end | |
64 | - | |
65 | -end |
plugins/serpro_captcha/test/unit/ext/environment_test.rb
... | ... | @@ -1,186 +0,0 @@ |
1 | -# require File.dirname(__FILE__) + '/../../../../../test/test_helper' | |
2 | -# | |
3 | -# class EnvironmentTest < ActiveSupport::TestCase | |
4 | -# | |
5 | -# def setup | |
6 | -# @enviroment = Environment.default | |
7 | -# end | |
8 | -# | |
9 | -# should 'have serpro_captcha_plugin variable defined' do | |
10 | -# assert_equal Hash, @enviroment.serpro_captcha_plugin.class | |
11 | -# end | |
12 | -# | |
13 | -# should 'return an empty hash by default on serpro_captcha_plugin_attributes method' do | |
14 | -# assert_equal Hash.new, @enviroment.serpro_captcha_plugin_attributes | |
15 | -# end | |
16 | -# | |
17 | -# should 'serpro_captcha_plugin_host= define the ldap host' do | |
18 | -# host = "http://something" | |
19 | -# @enviroment.serpro_captcha_plugin_host= host | |
20 | -# assert_equal host, @enviroment.serpro_captcha_plugin['host'] | |
21 | -# end | |
22 | -# | |
23 | -# should 'serpro_captcha_plugin_host return the defined ldap host' do | |
24 | -# host = "http://something" | |
25 | -# @enviroment.serpro_captcha_plugin_host= host | |
26 | -# assert_equal host, @enviroment.serpro_captcha_plugin_host | |
27 | -# end | |
28 | -# | |
29 | -# should 'serpro_captcha_plugin_port= define the ldap port' do | |
30 | -# value = 255 | |
31 | -# @enviroment.serpro_captcha_plugin_port= value | |
32 | -# assert_equal value, @enviroment.serpro_captcha_plugin['port'] | |
33 | -# end | |
34 | -# | |
35 | -# should 'serpro_captcha_plugin_port return the defined ldap port' do | |
36 | -# value = 255 | |
37 | -# @enviroment.serpro_captcha_plugin_port= value | |
38 | -# assert_equal value, @enviroment.serpro_captcha_plugin_port | |
39 | -# end | |
40 | -# | |
41 | -# should 'default serpro_captcha_plugin_port be 389' do | |
42 | -# assert_equal 389, @enviroment.serpro_captcha_plugin_port | |
43 | -# end | |
44 | -# | |
45 | -# should 'serpro_captcha_plugin_account= define the ldap acccount' do | |
46 | -# value = 'uid=sector,ou=Service,ou=corp,dc=company,dc=com,dc=br' | |
47 | -# @enviroment.serpro_captcha_plugin_account= value | |
48 | -# assert_equal value, @enviroment.serpro_captcha_plugin['account'] | |
49 | -# end | |
50 | -# | |
51 | -# should 'serpro_captcha_plugin_account return the defined ldap account' do | |
52 | -# value = 'uid=sector,ou=Service,ou=corp,dc=company,dc=com,dc=br' | |
53 | -# @enviroment.serpro_captcha_plugin_account= value | |
54 | -# assert_equal value, @enviroment.serpro_captcha_plugin_account | |
55 | -# end | |
56 | -# | |
57 | -# should 'serpro_captcha_plugin_account_password= define the ldap acccount_password' do | |
58 | -# value = 'password' | |
59 | -# @enviroment.serpro_captcha_plugin_account_password= value | |
60 | -# assert_equal value, @enviroment.serpro_captcha_plugin['account_password'] | |
61 | -# end | |
62 | -# | |
63 | -# should 'serpro_captcha_plugin_account_password return the defined ldap account password' do | |
64 | -# value = 'password' | |
65 | -# @enviroment.serpro_captcha_plugin_account_password= value | |
66 | -# assert_equal value, @enviroment.serpro_captcha_plugin_account_password | |
67 | -# end | |
68 | -# | |
69 | -# should 'serpro_captcha_plugin_base_dn= define the ldap base_dn' do | |
70 | -# value = 'dc=company,dc=com,dc=br' | |
71 | -# @enviroment.serpro_captcha_plugin_base_dn= value | |
72 | -# assert_equal value, @enviroment.serpro_captcha_plugin['base_dn'] | |
73 | -# end | |
74 | -# | |
75 | -# should 'serpro_captcha_plugin_base_dn return the defined ldap base_dn' do | |
76 | -# value = 'dc=company,dc=com,dc=br' | |
77 | -# @enviroment.serpro_captcha_plugin_base_dn= value | |
78 | -# assert_equal value, @enviroment.serpro_captcha_plugin_base_dn | |
79 | -# end | |
80 | -# | |
81 | -# should 'serpro_captcha_plugin_attr_login= define the ldap attr_login' do | |
82 | -# value = 'uid' | |
83 | -# @enviroment.serpro_captcha_plugin_attr_login= value | |
84 | -# assert_equal value, @enviroment.serpro_captcha_plugin['attr_login'] | |
85 | -# end | |
86 | -# | |
87 | -# should 'serpro_captcha_plugin_attr_login return the defined ldap attr_login' do | |
88 | -# value = 'uid' | |
89 | -# @enviroment.serpro_captcha_plugin_attr_login= value | |
90 | -# assert_equal value, @enviroment.serpro_captcha_plugin_attr_login | |
91 | -# end | |
92 | -# | |
93 | -# should 'serpro_captcha_plugin_attr_fullname= define the ldap attr_fullname' do | |
94 | -# value = 'Noosfero System' | |
95 | -# @enviroment.serpro_captcha_plugin_attr_fullname= value | |
96 | -# assert_equal value, @enviroment.serpro_captcha_plugin['attr_fullname'] | |
97 | -# end | |
98 | -# | |
99 | -# should 'serpro_captcha_plugin_attr_fullname return the defined ldap attr_fullname' do | |
100 | -# value = 'uid' | |
101 | -# @enviroment.serpro_captcha_plugin_attr_fullname= value | |
102 | -# assert_equal value, @enviroment.serpro_captcha_plugin_attr_fullname | |
103 | -# end | |
104 | -# | |
105 | -# | |
106 | -# should 'serpro_captcha_plugin_attr_mail= define the ldap attr_mail' do | |
107 | -# value = 'test@noosfero.com' | |
108 | -# @enviroment.serpro_captcha_plugin_attr_mail= value | |
109 | -# assert_equal value, @enviroment.serpro_captcha_plugin['attr_mail'] | |
110 | -# end | |
111 | -# | |
112 | -# should 'serpro_captcha_plugin_attr_mail return the defined ldap attr_mail' do | |
113 | -# value = 'test@noosfero.com' | |
114 | -# @enviroment.serpro_captcha_plugin_attr_mail= value | |
115 | -# assert_equal value, @enviroment.serpro_captcha_plugin_attr_mail | |
116 | -# end | |
117 | -# | |
118 | -# should 'serpro_captcha_plugin_onthefly_register= define the ldap onthefly_register' do | |
119 | -# value = '1' | |
120 | -# @enviroment.serpro_captcha_plugin_onthefly_register= value | |
121 | -# assert @enviroment.serpro_captcha_plugin['onthefly_register'] | |
122 | -# end | |
123 | -# | |
124 | -# should 'serpro_captcha_plugin_onthefly_register return true if ldap onthefly_register variable is defined as true' do | |
125 | -# value = '1' | |
126 | -# @enviroment.serpro_captcha_plugin_onthefly_register= value | |
127 | -# assert @enviroment.serpro_captcha_plugin_onthefly_register | |
128 | -# end | |
129 | -# | |
130 | -# should 'serpro_captcha_plugin_onthefly_register return false if ldap onthefly_register variable is defined as false' do | |
131 | -# value = '0' | |
132 | -# @enviroment.serpro_captcha_plugin_onthefly_register= value | |
133 | -# refute @enviroment.serpro_captcha_plugin_onthefly_register | |
134 | -# end | |
135 | -# | |
136 | -# should 'serpro_captcha_plugin_filter= define the ldap filter' do | |
137 | -# value = 'test' | |
138 | -# @enviroment.serpro_captcha_plugin_filter= value | |
139 | -# assert_equal value, @enviroment.serpro_captcha_plugin['filter'] | |
140 | -# end | |
141 | -# | |
142 | -# should 'serpro_captcha_plugin_filter return the defined ldap filter' do | |
143 | -# value = 'test' | |
144 | -# @enviroment.serpro_captcha_plugin_filter= value | |
145 | -# assert_equal value, @enviroment.serpro_captcha_plugin_filter | |
146 | -# end | |
147 | -# | |
148 | -# should 'serpro_captcha_plugin_tls= define the ldap tls' do | |
149 | -# value = '1' | |
150 | -# @enviroment.serpro_captcha_plugin_tls= value | |
151 | -# assert @enviroment.serpro_captcha_plugin['tls'] | |
152 | -# end | |
153 | -# | |
154 | -# should 'tls return true if ldap tls variable is defined as true' do | |
155 | -# value = '1' | |
156 | -# @enviroment.serpro_captcha_plugin_tls= value | |
157 | -# assert @enviroment.serpro_captcha_plugin_tls | |
158 | -# end | |
159 | -# | |
160 | -# should 'tls return false if ldap tls variable is defined as false' do | |
161 | -# value = '0' | |
162 | -# @enviroment.serpro_captcha_plugin_tls= value | |
163 | -# refute @enviroment.serpro_captcha_plugin_tls | |
164 | -# end | |
165 | -# | |
166 | -# should 'validates presence of host' do | |
167 | -# @enviroment.serpro_captcha_plugin= {:port => 3000} | |
168 | -# @enviroment.valid? | |
169 | -# | |
170 | -# assert @enviroment.errors.include?(:serpro_captcha_plugin_host) | |
171 | -# | |
172 | -# @enviroment.serpro_captcha_plugin_host= "http://somehost.com" | |
173 | -# @enviroment.valid? | |
174 | -# refute @enviroment.errors.include?(:serpro_captcha_plugin_host) | |
175 | -# end | |
176 | -# | |
177 | -# should 'validates presence of host only if some ldap configuration is defined' do | |
178 | -# @enviroment.valid? | |
179 | -# refute @enviroment.errors.include?(:serpro_captcha_plugin_host) | |
180 | -# | |
181 | -# @enviroment.serpro_captcha_plugin= {:port => 3000} | |
182 | -# @enviroment.valid? | |
183 | -# assert @enviroment.errors.include?(:serpro_captcha_plugin_host) | |
184 | -# end | |
185 | -# | |
186 | -# end |
plugins/serpro_captcha/test/unit/serpro_captcha_verification_test.rb
... | ... | @@ -1,109 +0,0 @@ |
1 | -require 'webmock' | |
2 | -include WebMock::API | |
3 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
4 | -require_relative '../test_helper' | |
5 | - | |
6 | -class SerproCaptchaVerificationTest < ActiveSupport::TestCase | |
7 | - | |
8 | - def setup | |
9 | - @environment = Environment.default | |
10 | - @environment.enabled_plugins = ['SerproCaptchaPlugin'] | |
11 | - @environment.serpro_captcha_verify_uri="http://www.somecompany.com:443/validate" | |
12 | - @environment.serpro_captcha_client_id='323232' | |
13 | - @environment.save! | |
14 | - @captcha_token = "642646" | |
15 | - @captcha_text = "44641441" | |
16 | - @captcha_verification_body = "#{@environment.serpro_captcha_client_id}&#{@captcha_token}&#{@captcha_text}" | |
17 | - end | |
18 | - | |
19 | - def login_with_captcha | |
20 | - store = Noosfero::API::SessionStore.create("captcha") | |
21 | - ## Initialize the data for the session store | |
22 | - store.data = [] | |
23 | - ## Put it back in cache | |
24 | - store.store | |
25 | - { "private_token" => "#{store.private_token}" } | |
26 | - end | |
27 | - | |
28 | - def create_article(name) | |
29 | - person = fast_create(Person, :environment_id => @environment.id) | |
30 | - fast_create(Article, :profile_id => person.id, :name => name) | |
31 | - end | |
32 | - | |
33 | - should 'register a user when there are no enabled captcha pluging' do | |
34 | - @environment.enabled_plugins = [] | |
35 | - @environment.save! | |
36 | - Environment.default.enable('skip_new_user_email_confirmation') | |
37 | - params = {:login => "newuserapi", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com" } | |
38 | - post "/api/v1/register?#{params.to_query}" | |
39 | - assert_equal 201, last_response.status | |
40 | - json = JSON.parse(last_response.body) | |
41 | - assert User['newuserapi'].activated? | |
42 | - assert json['user']['private_token'].present? | |
43 | - end | |
44 | - | |
45 | - should 'not register a user if captcha fails' do | |
46 | - fail_captcha_text @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
47 | - Environment.default.enable('skip_new_user_email_confirmation') | |
48 | - params = {:login => "newuserapi", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com", :txtToken_captcha_serpro_gov_br => @captcha_token, :captcha_text => @captcha_text} | |
49 | - post "/api/v1/register?#{params.to_query}" | |
50 | - assert_equal 403, last_response.status | |
51 | - json = JSON.parse(last_response.body) | |
52 | - assert_equal json["message"], _("Wrong captcha text, please try again") | |
53 | - end | |
54 | - | |
55 | - should 'verify_serpro_captcha' do | |
56 | - pass_captcha @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
57 | - scv = SerproCaptchaVerification.new | |
58 | - assert scv.verify_serpro_captcha(@environment.serpro_captcha_client_id, @captcha_token, @captcha_text, @environment.serpro_captcha_verify_uri) | |
59 | - end | |
60 | - | |
61 | - should 'fail captcha if user has not filled Serpro\' captcha text' do | |
62 | - pass_captcha @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
63 | - scv = SerproCaptchaVerification.new | |
64 | - hash = scv.verify_serpro_captcha(@environment.serpro_captcha_client_id, @captcha_token, nil, @environment.serpro_captcha_verify_uri) | |
65 | - assert hash[:user_message], _('Captcha text has not been filled') | |
66 | - end | |
67 | - | |
68 | - should 'fail captcha if Serpro\' captcha token has not been sent' do | |
69 | - pass_captcha @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
70 | - scv = SerproCaptchaVerification.new | |
71 | - hash = scv.verify_serpro_captcha(@environment.serpro_captcha_client_id, nil, @captcha_text, @environment.serpro_captcha_verify_uri) | |
72 | - assert hash[:javascript_console_message], _("Missing Serpro's Captcha token") | |
73 | - end | |
74 | - | |
75 | - should 'fail captcha text' do | |
76 | - fail_captcha_text @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
77 | - scv = SerproCaptchaVerification.new | |
78 | - hash = scv.verify_serpro_captcha(@environment.serpro_captcha_client_id, nil, @captcha_text, @environment.serpro_captcha_verify_uri) | |
79 | - assert hash[:javascript_console_message], _("Wrong captcha text, please try again") | |
80 | - end | |
81 | - | |
82 | - should 'not perform a vote without authentication' do | |
83 | - article = create_article('Article 1') | |
84 | - params = {} | |
85 | - params[:value] = 1 | |
86 | - | |
87 | - post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
88 | - json = JSON.parse(last_response.body) | |
89 | - assert_equal 401, last_response.status | |
90 | - end | |
91 | - | |
92 | - should 'perform a vote on an article identified by id' do | |
93 | - pass_captcha @environment.serpro_captcha_verify_uri, @captcha_verification_body | |
94 | - params = {} | |
95 | - params[:txtToken_captcha_serpro_gov_br]= @captcha_token | |
96 | - params[:captcha_text]= @captcha_text | |
97 | - post "/api/v1/login-captcha?#{params.to_query}" | |
98 | - json = JSON.parse(last_response.body) | |
99 | - article = create_article('Article 1') | |
100 | - params = {} | |
101 | - params[:private_token] = json['private_token'] | |
102 | - params[:value] = 1 | |
103 | - post "/api/v1/articles/#{article.id}/vote?#{params.to_query}" | |
104 | - json = JSON.parse(last_response.body) | |
105 | - assert_not_equal 401, last_response.status | |
106 | - assert_equal true, json['vote'] | |
107 | - end | |
108 | - | |
109 | -end |
plugins/serpro_captcha/views/serpro_captcha_plugin_admin/index.html.erb
... | ... | @@ -1,28 +0,0 @@ |
1 | -<h1><%= _("Serpro's Captcha Management") %> </h1> | |
2 | - | |
3 | -<%= labelled_form_for(:environment, :url => {:action => 'update'}) do |f| %> | |
4 | - | |
5 | -<table> | |
6 | - <tr> | |
7 | - <th><%= c_('Configuration') %></th> | |
8 | - <th><%= _('Value') %></th> | |
9 | - </tr> | |
10 | - <tr> | |
11 | - <td><%= _('Verify URI') %></td> | |
12 | - <td><%= text_field :environment, :serpro_captcha_verify_uri %></td> | |
13 | - </tr> | |
14 | - <tr> | |
15 | - <td><%= _('Client Id') %></td> | |
16 | - <td><%= text_field :environment, :serpro_captcha_client_id %></td> | |
17 | - </tr> | |
18 | -</table> | |
19 | - | |
20 | - | |
21 | -<div> | |
22 | - <% button_bar do %> | |
23 | - <%= submit_button('save', c_('Save changes')) %> | |
24 | - <%= button :back, _('Back to plugins administration panel'), :controller => 'plugins' %> | |
25 | - <% end %> | |
26 | -</div> | |
27 | - | |
28 | -<% end %> |