5
5
from roundup import date as rdate
6
6
from roundup import i18n
7
7
from roundup import password
8
- from roundup .anypy .strings import b2s
8
+ from roundup .anypy .strings import b2s , s2b
9
9
from roundup .cgi .wsgi_handler import RequestDispatcher
10
10
from .wsgi_liveserver import LiveServerTestCase
11
11
from . import db_test_base
@@ -377,7 +377,7 @@ def test_reauth_workflow(self):
377
377
378
378
enter good password
379
379
verify on user page (look for
380
- "(the default is 0) " hint for timezone)
380
+ "(the default is" hint for timezone)
381
381
verify new name present
382
382
verify success banner
383
383
"""
@@ -434,8 +434,16 @@ def get_fields(self):
434
434
return self .fields
435
435
436
436
437
+ # for some reason the lookup works with anydbm but
438
+ # returns a cursor closed error under postgresql.
439
+ # adding setup/teardown to TestPostgresWsgiServer
440
+ # with self.db = self.instance.open('admin') looks like
441
+ # it caused the wsgi server to hang. So hardcode the id.
442
+ # self.db.user.lookup('reauth')
443
+ reauth_id = '4'
444
+
437
445
user_url = "%s/user%s" % (self .url_base (),
438
- self . db . user . lookup ( 'reauth' ) )
446
+ reauth_id )
439
447
440
448
session , _response = self .create_login_session ()
441
449
@@ -522,8 +530,9 @@ def get_fields(self):
522
530
self .assertNotIn (b'id="reauth_form"' , pass_reauth .content )
523
531
self .assertNotIn (b'Please enter your password to continue with' ,
524
532
pass_reauth .content )
525
- self .assertIn (b'user 4 realname edited ok' , pass_reauth .content )
526
- self .assertIn (b'(the default is 0)' , pass_reauth .content )
533
+ self .assertIn (b'user %s realname edited ok' % s2b (reauth_id ),
534
+ pass_reauth .content )
535
+ self .assertIn (b'(the default is' , pass_reauth .content )
527
536
528
537
def test_cookie_attributes (self ):
529
538
session , _response = self .create_login_session ()
@@ -1831,25 +1840,49 @@ def setup_class(cls):
1831
1840
# set up and open a tracker
1832
1841
cls .instance = db_test_base .setupTracker (cls .dirname , cls .backend )
1833
1842
1843
+ # add an auditor that triggers a Reauth
1844
+ with open ("%s/detectors/reauth.py" % cls .dirname , "w" ) as f :
1845
+ auditor = dedent ("""
1846
+ from roundup.cgi.exceptions import Reauth
1847
+
1848
+ def trigger_reauth(db, cl, nodeid, newvalues):
1849
+ if 'realname' in newvalues and not hasattr(db, 'reauth_done'):
1850
+ raise Reauth('Add an optional message to the user')
1851
+
1852
+ def init(db):
1853
+ db.user.audit('set', trigger_reauth, priority=110)
1854
+ """ )
1855
+ f .write (auditor )
1856
+
1834
1857
# open the database
1835
1858
cls .db = cls .instance .open ('admin' )
1836
1859
1837
1860
# add a user without edit access for status.
1838
1861
cls .db .user .create (username = "fred" , roles = 'User' ,
1839
1862
password = password .
Password (
'sekrit' ),
address = '[email protected] ' )
1840
1863
1864
+ # add a user for reauth tests
1865
+ cls .db .user .create (username = "reauth" ,
1866
+ realname = "reauth test user" ,
1867
+ password = password .Password ("reauth" ),
1868
+ address = "[email protected] " ,
roles = "User" )
1869
+
1841
1870
# set the url the test instance will run at.
1842
1871
cls .db .config ['TRACKER_WEB' ] = cls .tracker_web
1843
1872
# set up mailhost so errors get reported to debuging capture file
1844
1873
cls .db .config .MAILHOST = "localhost"
1845
1874
cls .db .config .MAIL_HOST = "localhost"
1846
1875
cls .db .config .MAIL_DEBUG = "../_test_tracker_mail.log"
1847
1876
1877
+ # also report it in the web.
1878
+ cls .db .config .WEB_DEBUG = "yes"
1879
+
1848
1880
# added to enable csrf forgeries/CORS to be tested
1849
1881
cls .db .config .WEB_CSRF_ENFORCE_HEADER_ORIGIN = "required"
1850
1882
cls .db .config .WEB_ALLOWED_API_ORIGINS = "https://client.com"
1851
1883
cls .db .config ['WEB_CSRF_ENFORCE_HEADER_X-REQUESTED-WITH' ] = "required"
1852
1884
1885
+ # use native indexer
1853
1886
cls .db .config .INDEXER = "native-fts"
1854
1887
1855
1888
# disable web login rate limiting. The fast rate of tests
@@ -1867,6 +1900,8 @@ def setup_class(cls):
1867
1900
# re-open the database to get the updated INDEXER
1868
1901
cls .db = cls .instance .open ('admin' )
1869
1902
1903
+ # add an issue to allow testing retrieval.
1904
+ # also used for text searching.
1870
1905
result = cls .db .issue .create (title = "foo bar RESULT" )
1871
1906
1872
1907
# add a message to allow retrieval
@@ -1875,6 +1910,16 @@ def setup_class(cls):
1875
1910
date = rdate .Date (),
1876
1911
messageid = "test-msg-id" )
1877
1912
1913
+ # add a query using @current_user
1914
+ result = cls .db .query .create (
1915
+ klass = "issue" ,
1916
+ name = "I created" ,
1917
+ private_for = None ,
1918
+ url = ("@columns=title,id,activity,status,assignedto&"
1919
+ "@sort=activity&@group=priority&@filter=creator&"
1920
+ "@pagesize=50&@startwith=0&creator=%40current_user" )
1921
+ )
1922
+
1878
1923
cls .db .commit ()
1879
1924
cls .db .close ()
1880
1925
@@ -1899,8 +1944,7 @@ def test_native_fts(self):
1899
1944
1900
1945
@skip_requests
1901
1946
class TestApiRateLogin (WsgiSetup ):
1902
- """Class to run test in BaseTestCases with the cache_tracker
1903
- feature flag enabled when starting the wsgi server
1947
+ """Test api rate limiting on login use sqlite db.
1904
1948
"""
1905
1949
1906
1950
backend = 'sqlite'
0 commit comments