示例#1
0
文件: test_auth.py 项目: unikmhz/npui
    def test_generate_nonce(self):
        nonce = _generate_nonce(self.ts, 'secret')
        self.assertEqual(len(nonce), len(self.ts) + 50)
        self.assertRegex(nonce, r'^\d{10,11}:[0-9A-F]{16}:[0-9a-fA-F]{32}$')

        parts = nonce.split(':')
        self.assertEqual(parts[0], self.ts)

        nonce2 = _generate_nonce(self.ts, 'secret', parts[1])
        self.assertEqual(nonce, nonce2)
示例#2
0
    def test_generate_nonce(self):
        nonce = _generate_nonce(self.ts, 'secret')
        self.assertEqual(len(nonce), len(self.ts) + 50)
        self.assertRegex(nonce, r'^\d{10,11}:[0-9A-F]{16}:[0-9a-fA-F]{32}$')

        parts = nonce.split(':')
        self.assertEqual(parts[0], self.ts)

        nonce2 = _generate_nonce(self.ts, 'secret', parts[1])
        self.assertEqual(nonce, nonce2)
示例#3
0
文件: test_auth.py 项目: unikmhz/npui
    def test_unauth_ok(self):
        nonce = _generate_nonce(self.ts, 'secret')
        self.req.authorization = ('Digest',
                                  {'username': '******',
                                   'realm': 'realm',
                                   'nonce': nonce,
                                   'uri': '/index.html',
                                   'response':
                                       'fe6636cdb8b1733ecca83dcb14b13323',
                                   'cnonce': '1f3f713c',
                                   'nc': '00000001',
                                   'opaque': 'NPDIGEST',
                                   'algorithm': 'MD5'})

        ret = self.pol.unauthenticated_userid(self.req)

        self.assertIsNone(self.req.response.www_authenticate)
        self.assertEqual(ret, 'u:testuser')
示例#4
0
    def test_unauth_ok(self):
        nonce = _generate_nonce(self.ts, 'secret')
        self.req.authorization = ('Digest', {
            'username': '******',
            'realm': 'realm',
            'nonce': nonce,
            'uri': '/index.html',
            'response': 'fe6636cdb8b1733ecca83dcb14b13323',
            'cnonce': '1f3f713c',
            'nc': '00000001',
            'opaque': 'NPDIGEST',
            'algorithm': 'MD5'
        })

        ret = self.pol.unauthenticated_userid(self.req)

        self.assertIsNone(self.req.response.www_authenticate)
        self.assertEqual(ret, 'u:testuser')
示例#5
0
	def test_ep_callback_ok(self):
		self.callback.return_value = ['g:testgroup1', 'g:testgroup2']
		nonce = _generate_nonce(self.ts, 'secret')
		self.req.authorization = ('Digest', {
			'username'  : 'testuser',
			'realm'     : 'realm',
			'nonce'     : nonce,
			'uri'       : '/index.html',
			'response'  : 'fe6636cdb8b1733ecca83dcb14b13323',
			'cnonce'    : '1f3f713c',
			'nc'        : '00000001',
			'opaque'    : 'NPDIGEST',
			'algorithm' : 'MD5'
		})

		ret = self.pol.effective_principals(self.req)

		self.assertIsNone(self.req.response.www_authenticate)
		self.assertEqual(ret, [Everyone, Authenticated, 'u:testuser', 'g:testgroup1', 'g:testgroup2'])
		self.callback.assert_called_once_with(self.req.authorization[1], self.req)
示例#6
0
	def test_auth_callback_failed(self):
		self.callback.return_value = None
		nonce = _generate_nonce(self.ts, 'secret')
		self.req.authorization = ('Digest', {
			'username'  : 'testuser',
			'realm'     : 'realm',
			'nonce'     : nonce,
			'uri'       : '/index.html',
			'response'  : 'fe6636cdb8b1733ecca83dcb14b13323',
			'cnonce'    : '1f3f713c',
			'nc'        : '00000001',
			'opaque'    : 'NPDIGEST',
			'algorithm' : 'MD5'
		})

		ret = self.pol.authenticated_userid(self.req)

		self.assertIsNotNone(self.req.response.www_authenticate)
		self.assertIsNone(ret)
		self.callback.assert_called_once_with(self.req.authorization[1], self.req)
示例#7
0
    def test_ep_callback_failed(self):
        self.callback.return_value = None
        nonce = _generate_nonce(self.ts, 'secret')
        self.req.authorization = ('Digest', {
            'username': '******',
            'realm': 'realm',
            'nonce': nonce,
            'uri': '/index.html',
            'response': 'fe6636cdb8b1733ecca83dcb14b13323',
            'cnonce': '1f3f713c',
            'nc': '00000001',
            'opaque': 'NPDIGEST',
            'algorithm': 'MD5'
        })

        ret = self.pol.effective_principals(self.req)

        self.assertIsNotNone(self.req.response.www_authenticate)
        self.assertEqual(ret, [Everyone])
        self.callback.assert_called_once_with(self.req.authorization[1],
                                              self.req)
示例#8
0
    def test_auth_callback_ok(self):
        self.callback.return_value = ['g:testgroup1', 'g:testgroup2']
        nonce = _generate_nonce(self.ts, 'secret')
        self.req.authorization = ('Digest', {
            'username': '******',
            'realm': 'realm',
            'nonce': nonce,
            'uri': '/index.html',
            'response': 'fe6636cdb8b1733ecca83dcb14b13323',
            'cnonce': '1f3f713c',
            'nc': '00000001',
            'opaque': 'NPDIGEST',
            'algorithm': 'MD5'
        })

        ret = self.pol.authenticated_userid(self.req)

        self.assertIsNone(self.req.response.www_authenticate)
        self.assertEqual(ret, 'u:testuser')
        self.callback.assert_called_once_with(self.req.authorization[1],
                                              self.req)