|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +# Copyright (c) 2002-2017 "Neo Technology," |
| 5 | +# Network Engine for Objects in Lund AB [http://neotechnology.com] |
| 6 | +# |
| 7 | +# This file is part of Neo4j. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | + |
| 21 | +from unittest import TestCase |
| 22 | +from neo4j.v1.security import kerberos_auth, basic_auth, custom_auth |
| 23 | + |
| 24 | +class AuthTokenTestCase(TestCase): |
| 25 | + |
| 26 | + def test_should_generate_kerberos_auth_token_correctly(self): |
| 27 | + auth = kerberos_auth("I am a base64 service ticket") |
| 28 | + assert auth.scheme == "kerberos" |
| 29 | + assert auth.principal == "" |
| 30 | + assert auth.credentials == "I am a base64 service ticket" |
| 31 | + assert not auth.realm |
| 32 | + assert not hasattr(auth, "parameters") |
| 33 | + |
| 34 | + def test_should_generate_basic_auth_without_realm_correctly(self): |
| 35 | + auth = basic_auth("molly", "meoooow") |
| 36 | + assert auth.scheme == "basic" |
| 37 | + assert auth.principal == "molly" |
| 38 | + assert auth.credentials == "meoooow" |
| 39 | + assert not auth.realm |
| 40 | + assert not hasattr(auth, "parameters") |
| 41 | + |
| 42 | + def test_should_generate_base_auth_with_realm_correctly(self): |
| 43 | + auth = basic_auth("molly", "meoooow", "cat_caffe") |
| 44 | + assert auth.scheme == "basic" |
| 45 | + assert auth.principal == "molly" |
| 46 | + assert auth.credentials == "meoooow" |
| 47 | + assert auth.realm == "cat_caffe" |
| 48 | + assert not hasattr(auth, "parameters") |
| 49 | + |
| 50 | + def test_should_generate_custom_auth_correctly(self): |
| 51 | + auth = custom_auth("molly", "meoooow", "cat_caffe", "cat", age="1", color="white") |
| 52 | + assert auth.scheme == "cat" |
| 53 | + assert auth.principal == "molly" |
| 54 | + assert auth.credentials == "meoooow" |
| 55 | + assert auth.realm == "cat_caffe" |
| 56 | + assert auth.parameters == {"age": "1", "color": "white"} |
0 commit comments