Fix compiler warning due to missing function prototype.
[svn.git] / subversion / bindings / swig / python / tests / auth.py
blobae9a2de47fe63f2edfa0f3e23bb30ecdddb9309c
1 import unittest, os, setup_path
3 from svn import core
5 class SubversionAuthTestCase(unittest.TestCase):
6 """Test cases for the Subversion auth."""
8 def test_open(self):
9 baton = core.svn_auth_open([])
10 self.assert_(baton is not None)
12 def test_set_parameter(self):
13 baton = core.svn_auth_open([])
14 core.svn_auth_set_parameter(baton, "name", "somedata")
15 core.svn_auth_set_parameter(baton, "name", None)
16 core.svn_auth_set_parameter(baton, "name", 2)
17 core.svn_auth_set_parameter(baton, "name",
18 core.svn_auth_ssl_server_cert_info_t())
20 def test_invalid_cred_kind(self):
21 baton = core.svn_auth_open([])
22 self.assertRaises(core.SubversionException,
23 lambda: core.svn_auth_first_credentials(
24 "unknown", "somerealm", baton))
26 def test_credentials_get_username(self):
27 def myfunc(realm, maysave, pool):
28 self.assertEquals("somerealm", realm)
29 username_cred = core.svn_auth_cred_username_t()
30 username_cred.username = "bar"
31 username_cred.may_save = False
32 return username_cred
33 baton = core.svn_auth_open([core.svn_auth_get_username_prompt_provider(myfunc, 1)])
34 creds = core.svn_auth_first_credentials(
35 core.SVN_AUTH_CRED_USERNAME, "somerealm", baton)
36 self.assert_(creds is not None)
38 def test_credentials_get_simple(self):
39 def myfunc(realm, username, may_save, pool):
40 self.assertEquals("somerealm", realm)
41 simple_cred = core.svn_auth_cred_simple_t()
42 simple_cred.username = "mijnnaam"
43 simple_cred.password = "geheim"
44 simple_cred.may_save = False
45 return simple_cred
46 baton = core.svn_auth_open([core.svn_auth_get_simple_prompt_provider(myfunc, 1)])
47 creds = core.svn_auth_first_credentials(
48 core.SVN_AUTH_CRED_SIMPLE, "somerealm", baton)
49 self.assert_(creds is not None)
51 def test_credentials_get_ssl_client_cert(self):
52 def myfunc(realm, may_save, pool):
53 self.assertEquals("somerealm", realm)
54 ssl_cred = core.svn_auth_cred_ssl_client_cert_t()
55 ssl_cred.cert_file = "my-certs-file"
56 ssl_cred.may_save = False
57 return ssl_cred
58 baton = core.svn_auth_open([core.svn_auth_get_ssl_client_cert_prompt_provider(myfunc, 1)])
59 creds = core.svn_auth_first_credentials(
60 core.SVN_AUTH_CRED_SSL_CLIENT_CERT, "somerealm", baton)
61 self.assert_(creds is not None)
63 def test_credentials_get_ssl_client_cert_pw(self):
64 def myfunc(realm, may_save, pool):
65 self.assertEquals("somerealm", realm)
66 ssl_cred_pw = core.svn_auth_cred_ssl_client_cert_pw_t()
67 ssl_cred_pw.password = "supergeheim"
68 ssl_cred_pw.may_save = False
69 return ssl_cred_pw
70 baton = core.svn_auth_open([core.svn_auth_get_ssl_client_cert_pw_prompt_provider(myfunc, 1)])
71 creds = core.svn_auth_first_credentials(
72 core.SVN_AUTH_CRED_SSL_CLIENT_CERT_PW, "somerealm", baton)
73 self.assert_(creds is not None)
75 def test_credentials_get_ssl_server_trust(self):
76 def myfunc(realm, failures, cert_info, may_save, pool):
77 self.assertEquals("somerealm", realm)
78 ssl_trust = core.svn_auth_cred_ssl_server_trust_t()
79 ssl_trust.accepted_failures = 0
80 ssl_trust.may_save = False
81 return ssl_trust
82 baton = core.svn_auth_open([core.svn_auth_get_ssl_server_trust_prompt_provider(myfunc)])
83 core.svn_auth_set_parameter(baton, core.SVN_AUTH_PARAM_SSL_SERVER_FAILURES,
84 "2")
85 cert_info = core.svn_auth_ssl_server_cert_info_t()
86 core.svn_auth_set_parameter(baton, core.SVN_AUTH_PARAM_SSL_SERVER_CERT_INFO,
87 cert_info)
88 creds = core.svn_auth_first_credentials(
89 core.SVN_AUTH_CRED_SSL_SERVER_TRUST, "somerealm", baton)
90 self.assert_(creds is not None)
92 def suite():
93 return unittest.makeSuite(SubversionAuthTestCase, 'test')
95 if __name__ == '__main__':
96 runner = unittest.TextTestRunner()
97 runner.run(suite())