Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nginx-redirector
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
eterfund
nginx-redirector
Commits
2c60ba57
Commit
2c60ba57
authored
Apr 22, 2022
by
Soldatoff
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test and files for it. Tests for working with custom names
parent
36a4d1b2
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
264 additions
and
4 deletions
+264
-4
name_test.map
redirector/tests/name_test.map
+77
-0
name_tests.conf
redirector/tests/nginx/location-includes/name_tests.conf
+10
-0
name_tests.map
redirector/tests/nginx/maps/name_tests.map
+24
-0
name_tests_permanent_options.map
redirector/tests/nginx/maps/name_tests_permanent_options.map
+5
-0
name_tests_status=301_options.map
...rector/tests/nginx/maps/name_tests_status=301_options.map
+6
-0
name_tests.conf
...r/tests/nginx_test_case/location-includes/name_tests.conf
+10
-0
prefix.conf
...ector/tests/nginx_test_case/location-includes/prefix.conf
+3
-0
name_tests.map
redirector/tests/nginx_test_case/maps/name_tests.map
+24
-0
name_tests_permanent_options.map
...sts/nginx_test_case/maps/name_tests_permanent_options.map
+5
-0
name_tests_status=301_options.map
...ts/nginx_test_case/maps/name_tests_status=301_options.map
+6
-0
redirector_nametest.py
redirector/tests/redirector_nametest.py
+83
-0
redirector_test.py
redirector/tests/redirector_test.py
+8
-3
test.yaml
redirector/tests/test.yaml
+3
-1
No files found.
redirector/tests/name_test.map
0 → 100644
View file @
2c60ba57
#RedirectMatch
/name.html /name123.html
# RewriteRule ^$ /cgi-bin/index.cgi [L]
^$ /cgi-bin/index.cgi
# RewriteRule ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2 [L]
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2
# RedirectMatch 301 ^/manual/(.*)$ http://www.php.net/manual/$1
^/manual/(.*)$ http://www.php.net/manual/$1
# RewriteRule ^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1 [L]
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1
# RewriteRule ^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 [L]
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2
# RedirectMatch 301 /java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2
# RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2 [L]
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2
# RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3
# RewriteRule ^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles [L]
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles
# Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html [status=301]
# RewriteRule ^contact\.html$ /cgi-bin/index.cgi?op=contact [L]
^contact\.html$ /cgi-bin/index.cgi?op=contact
# RewriteRule ^premium\.html$ /cgi-bin/index.cgi?op=payments [L]
^premium\.html$ /cgi-bin/index.cgi?op=payments
# RedirectMatch 301 ^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html
# RewriteRule ^login\.html$ /cgi-bin/index.cgi?op=login [L]
^login\.html$ /cgi-bin/index.cgi?op=login
# Redirect 301 /2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html [status=301]
# RewriteRule ^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1 [L]
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1
# RewriteRule ^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1 [L]
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1
# Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html [status=301]
# RewriteRule ^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1 [L]
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1
# RewriteRule ^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1 [L]
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1
# RewriteRule ^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 [L]
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2
# RedirectMatch 301 ^/200([0-9])/([^01])(.*)$ /$2$3
^/200([0-9])/([^01])(.*)$ /$2$3
# RewriteRule ^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1 [L]
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1
# RewriteRule ^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1 [L]
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1
# RewriteRule ^box$ /cgi-bin/index_box.cgi [L]
^box$ /cgi-bin/index_box.cgi
redirector/tests/nginx/location-includes/name_tests.conf
0 → 100644
View file @
2c60ba57
if
($
name_tests_redirect
) {
rewrite
^/(.*)$ $
name_tests_redirect
redirect
;
}
if
($
name_tests_permanent_redirect
) {
rewrite
^/(.*)$ $
name_tests_permanent_redirect
permanent
;
}
if
($
name_tests_status
=
301
_
redirect
) {
rewrite
^/(.*)$ $
name_tests_status
=
301
_
redirect
redirect
;
return
status
=
301
;
}
redirector/tests/nginx/maps/name_tests.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_redirect {
/name.html /name123.html;
^$ /cgi-bin/index.cgi;
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2;
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1;
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3;
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles;
^contact\.html$ /cgi-bin/index.cgi?op=contact;
^premium\.html$ /cgi-bin/index.cgi?op=payments;
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html;
^login\.html$ /cgi-bin/index.cgi?op=login;
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1;
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1;
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1;
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1;
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2;
^/200([0-9])/([^01])(.*)$ /$2$3;
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1;
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1;
^box$ /cgi-bin/index_box.cgi;
}
\ No newline at end of file
redirector/tests/nginx/maps/name_tests_permanent_options.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_permanent_redirect {
^/manual/(.*)$ http://www.php.net/manual/$1;
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2;
}
\ No newline at end of file
redirector/tests/nginx/maps/name_tests_status=301_options.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_status=301_redirect {
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html;
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
}
\ No newline at end of file
redirector/tests/nginx_test_case/location-includes/name_tests.conf
0 → 100644
View file @
2c60ba57
if
($
name_tests_redirect
) {
rewrite
^/(.*)$ $
name_tests_redirect
redirect
;
}
if
($
name_tests_permanent_redirect
) {
rewrite
^/(.*)$ $
name_tests_permanent_redirect
permanent
;
}
if
($
name_tests_status
=
301
_
redirect
) {
rewrite
^/(.*)$ $
name_tests_status
=
301
_
redirect
redirect
;
return
status
=
301
;
}
redirector/tests/nginx_test_case/location-includes/prefix.conf
0 → 100644
View file @
2c60ba57
if
($
prefix_redirect
) {
rewrite
^/
prefix
/(.*)$ $
prefix_redirect
redirect
;
}
redirector/tests/nginx_test_case/maps/name_tests.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_redirect {
/name.html /name123.html;
^$ /cgi-bin/index.cgi;
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2;
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1;
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3;
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles;
^contact\.html$ /cgi-bin/index.cgi?op=contact;
^premium\.html$ /cgi-bin/index.cgi?op=payments;
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html;
^login\.html$ /cgi-bin/index.cgi?op=login;
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1;
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1;
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1;
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1;
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2;
^/200([0-9])/([^01])(.*)$ /$2$3;
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1;
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1;
^box$ /cgi-bin/index_box.cgi;
}
\ No newline at end of file
redirector/tests/nginx_test_case/maps/name_tests_permanent_options.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_permanent_redirect {
^/manual/(.*)$ http://www.php.net/manual/$1;
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2;
}
\ No newline at end of file
redirector/tests/nginx_test_case/maps/name_tests_status=301_options.map
0 → 100644
View file @
2c60ba57
map $uri $name_tests_status=301_redirect {
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html;
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
}
\ No newline at end of file
redirector/tests/redirector_nametest.py
0 → 100644
View file @
2c60ba57
import
unittest
import
os
from
redirector.tests.utils
import
get_abs_path
,
get_rel_path
from
redirector.redirector
import
*
from
redirector.utils
import
generators
from
redirector.utils
import
parser
from
redirector.utils.const
import
MAPS_DIR
,
CONFIG_DIR
,
CONFIG
class
EqualRedirectorTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
redirector
=
Redirector
()
def
test_equal_namemap
(
self
):
abs_yaml_path
=
get_abs_path
(
CONFIG
)
abs_test_path
=
get_abs_path
(
'name_test.map'
)
self
.
redirector
.
generate
(
abs_yaml_path
,
abs_test_path
)
abs_res_conf_path
=
get_rel_path
(
"{}/name_tests.conf"
.
format
(
CONFIG_DIR
))
res_conf_file
=
open
(
abs_res_conf_path
,
'r'
)
res_conf_lines
=
[]
for
line
in
res_conf_file
:
if
len
(
line
)
>
2
or
not
line
.
startswith
(
'#'
):
res_conf_lines
.
append
(
line
)
res_conf_file
.
close
()
maps_dir
=
get_rel_path
(
MAPS_DIR
)
abs_res_map_paths
=
[
"{}/name_tests.map"
.
format
(
maps_dir
),
"{}/name_tests_permanent_options.map"
.
format
(
maps_dir
),
"{}/name_tests_status=301_options.map"
.
format
(
maps_dir
)
]
res_map_lines
=
[]
for
path
in
abs_res_map_paths
:
f
=
open
(
path
,
'r'
)
for
line
in
f
:
if
len
(
line
)
>
2
or
not
line
.
startswith
(
'#'
):
res_map_lines
.
append
(
line
)
f
.
close
()
abs_test_conf_path
=
get_rel_path
(
'nginx/location-includes/name_tests.conf'
)
test_conf_file
=
open
(
abs_test_conf_path
,
'r'
)
test_conf_lines
=
[]
for
line
in
test_conf_file
:
if
len
(
line
)
>
2
or
not
line
.
startswith
(
'#'
):
test_conf_lines
.
append
(
line
)
test_conf_file
.
close
()
test_maps_dir
=
get_rel_path
(
'nginx/maps'
)
abs_test_map_paths
=
[
"{}/name_tests.map"
.
format
(
test_maps_dir
),
"{}/name_tests_permanent_options.map"
.
format
(
test_maps_dir
),
"{}/name_tests_status=301_options.map"
.
format
(
test_maps_dir
)
]
test_map_lines
=
[]
for
path
in
abs_test_map_paths
:
f
=
open
(
path
,
'r'
)
for
line
in
f
:
if
len
(
line
)
>
2
or
not
line
.
startswith
(
'#'
):
test_map_lines
.
append
(
line
)
f
.
close
()
# unittest.TestCase.maxDiff = None
self
.
assertEqual
(
res_conf_lines
,
test_conf_lines
)
self
.
assertEqual
(
res_map_lines
,
test_map_lines
)
# for path in abs_res_map_paths:
# os.remove(path)
# os.remove(abs_res_conf_path)
redirector/tests/redirector_test.py
View file @
2c60ba57
import
unittest
import
os
from
redirector.tests.utils
import
get_abs_path
,
get_rel_path
from
redirector.redirector
import
*
...
...
@@ -14,6 +16,7 @@ class EqualRedirectorTest(unittest.TestCase):
def
test_equal_map
(
self
):
abs_yaml_path
=
get_abs_path
(
CONFIG
)
abs_test_path
=
get_abs_path
(
'test.map'
)
self
.
redirector
.
generate
(
abs_yaml_path
,
abs_test_path
)
abs_res_conf_path
=
get_rel_path
(
"{}/test.conf"
.
format
(
CONFIG_DIR
))
...
...
@@ -25,7 +28,7 @@ class EqualRedirectorTest(unittest.TestCase):
res_conf_lines
.
append
(
line
)
res_conf_file
.
close
()
maps_dir
=
get_rel_path
(
MAPS_DIR
)
abs_res_map_paths
=
[
"{}/test.map"
.
format
(
maps_dir
),
...
...
@@ -43,8 +46,6 @@ class EqualRedirectorTest(unittest.TestCase):
res_map_lines
.
append
(
line
)
f
.
close
()
self
.
redirector
.
generate
(
abs_yaml_path
,
abs_test_path
)
abs_test_conf_path
=
get_rel_path
(
'nginx/location-includes/test.conf'
)
test_conf_file
=
open
(
abs_test_conf_path
,
'r'
)
...
...
@@ -76,4 +77,8 @@ class EqualRedirectorTest(unittest.TestCase):
self
.
assertEqual
(
res_conf_lines
,
test_conf_lines
)
self
.
assertEqual
(
res_map_lines
,
test_map_lines
)
# for path in abs_res_map_paths:
# os.remove(path)
# os.remove(abs_res_conf_path)
redirector/tests/test.yaml
View file @
2c60ba57
...
...
@@ -2,4 +2,6 @@ projects:
-
map
:
redirector/tests/test.map
prefix
:
/test
name
:
/
-
map
:
redirector/tests/name_test.map
prefix
:
/
name
:
/name
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment