|
1 |
# frozen_string_literal: true
|
|
2 |
|
|
3 |
# Redmine - project management software
|
|
4 |
# Copyright (C) 2006- Jean-Philippe Lang
|
|
5 |
#
|
|
6 |
# This program is free software; you can redistribute it and/or
|
|
7 |
# modify it under the terms of the GNU General Public License
|
|
8 |
# as published by the Free Software Foundation; either version 2
|
|
9 |
# of the License, or (at your option) any later version.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
# GNU General Public License for more details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License
|
|
17 |
# along with this program; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
19 |
|
|
20 |
require_relative '../test_helper'
|
|
21 |
|
|
22 |
class OauthRedirectUriTest < ActiveSupport::TestCase
|
|
23 |
def test_http_redirect_uri_should_be_allowed_for_loopback_hosts
|
|
24 |
%w[
|
|
25 |
http://localhost:3000/callback
|
|
26 |
http://127.0.0.1:3000/callback
|
|
27 |
http://[::1]:3000/callback
|
|
28 |
http://app.localhost:3000/callback
|
|
29 |
].each do |uri|
|
|
30 |
assert_empty redirect_uri_errors(uri), uri
|
|
31 |
end
|
|
32 |
end
|
|
33 |
|
|
34 |
def test_http_redirect_uri_should_be_rejected_for_other_hosts
|
|
35 |
%w[
|
|
36 |
http://example.com/callback
|
|
37 |
http://localhost.example.com/callback
|
|
38 |
http://notlocalhost/callback
|
|
39 |
].each do |uri|
|
|
40 |
assert_not_empty redirect_uri_errors(uri), uri
|
|
41 |
end
|
|
42 |
end
|
|
43 |
|
|
44 |
private
|
|
45 |
|
|
46 |
def redirect_uri_errors(redirect_uri)
|
|
47 |
application = Doorkeeper::Application.new(name: 'test', redirect_uri: redirect_uri)
|
|
48 |
application.valid?
|
|
49 |
application.errors[:redirect_uri]
|
|
50 |
end
|
|
51 |
end
|