forked from ksauzz/krbticket
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
198 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ build | |
dist | ||
*egg-info | ||
__pycache__ | ||
venv | ||
.venv | ||
.coverage | ||
htmlcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM ubuntu:18.04 | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
python3-pip \ | ||
python3-setuptools \ | ||
gettext \ | ||
krb5-user && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
COPY README.md setup.py entrypoint.sh pytest.ini /app/ | ||
COPY krbticket /app/krbticket | ||
COPY tests /app/tests | ||
COPY tests/conf/krb5.conf.tmpl tests/conf/krb5.keytab /etc/ | ||
RUN chmod 755 /app/entrypoint.sh | ||
|
||
ENV KRB5_HOST localhost | ||
|
||
ENTRYPOINT ["/app/entrypoint.sh"] | ||
CMD ["pytest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
envsubst < /etc/krb5.conf.tmpl > /etc/krb5.conf | ||
pip3 install -e '.[test]' | ||
|
||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = -v -s --cov=krbticket --cov-report=html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[libdefaults] | ||
default_realm = EXAMPLE.COM | ||
dns_lookup_kdc = false | ||
dns_lookup_realm = false | ||
ticket_lifetime = 7d | ||
renew_lifetime = 28d | ||
forwardable = true | ||
default_tgs_enctypes = rc4-hmac | ||
default_tkt_enctypes = rc4-hmac | ||
permitted_enctypes = rc4-hmac | ||
udp_preference_limit = 1 | ||
kdc_timeout = 3000 | ||
|
||
[realms] | ||
EXAMPLE.COM = { | ||
kdc = localhost | ||
admin_server = localhost | ||
default_domain = EXAMPLE.COM | ||
} | ||
|
||
[domain_realm] | ||
example.com = EXAMPLE.COM | ||
.example.com = EXAMPLE.COM | ||
|
||
[logging] | ||
default = CONSOLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[libdefaults] | ||
default_realm = EXAMPLE.COM | ||
dns_lookup_kdc = false | ||
dns_lookup_realm = false | ||
ticket_lifetime = 7d | ||
renew_lifetime = 28d | ||
forwardable = true | ||
default_tgs_enctypes = rc4-hmac | ||
default_tkt_enctypes = rc4-hmac | ||
permitted_enctypes = rc4-hmac | ||
udp_preference_limit = 1 | ||
kdc_timeout = 3000 | ||
|
||
[realms] | ||
EXAMPLE.COM = { | ||
kdc = ${KRB5_HOST} | ||
admin_server = ${KRB5_HOST} | ||
default_domain = EXAMPLE.COM | ||
} | ||
|
||
[domain_realm] | ||
example.com = EXAMPLE.COM | ||
.example.com = EXAMPLE.COM | ||
|
||
[logging] | ||
default = CONSOLE |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
from krbticket import KrbConfig | ||
|
||
DEFAULT_PRINCIPAL = '[email protected]' | ||
DEFAULT_KEYTAB = './tests/conf/krb5.keytab' | ||
DEFAULT_TICKET_LIFETIME = '2s' | ||
|
||
def assert_ticket(t1, t2): | ||
assert t1.principal == t2.principal | ||
assert t1.file == t2.file | ||
assert t1.starting == t2.starting | ||
assert t1.expires == t2.expires | ||
assert t1.service_principal == t2.service_principal | ||
|
||
|
||
@pytest.fixture | ||
def config(): | ||
return KrbConfig(DEFAULT_PRINCIPAL, DEFAULT_KEYTAB, ticket_lifetime=DEFAULT_TICKET_LIFETIME) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from krbticket import KrbConfig, KrbCommand | ||
from helper import config | ||
|
||
|
||
def test_commands(config): | ||
KrbCommand.kdestroy(config) | ||
KrbCommand.kinit(config) | ||
KrbCommand.renewal(config) | ||
KrbCommand.klist(config) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from krbticket import KrbTicket, KrbCommand | ||
from krbticket.ticket import NoCredentialFound | ||
from helper import * | ||
import time | ||
|
||
|
||
def test_init(config): | ||
KrbCommand.kdestroy(config) | ||
ticket1 = KrbTicket.init_by_config(config) | ||
ticket2 = KrbTicket.init(DEFAULT_PRINCIPAL, DEFAULT_KEYTAB) | ||
assert ticket1.principal == ticket2.principal | ||
assert ticket1.file == ticket2.file | ||
|
||
|
||
def test_get(config): | ||
KrbCommand.kdestroy(config) | ||
with pytest.raises(NoCredentialFound): | ||
KrbTicket.get(DEFAULT_PRINCIPAL, DEFAULT_KEYTAB) | ||
|
||
assert_ticket( | ||
KrbTicket.init_by_config(config), | ||
KrbTicket.get(DEFAULT_KEYTAB, DEFAULT_PRINCIPAL)) | ||
|
||
|
||
def test_ticket(config): | ||
KrbCommand.kdestroy(config) | ||
ticket = KrbTicket.init_by_config(config) | ||
assert ticket.config == config | ||
assert ticket.file | ||
assert ticket.principal == '[email protected]' | ||
assert ticket.starting | ||
assert ticket.expires | ||
assert ticket.service_principal | ||
|
||
|
||
def test_updater(config): | ||
KrbCommand.kdestroy(config) | ||
ticket = KrbTicket.init_by_config(config) | ||
updater = ticket.updater(interval=1) | ||
updater.start() | ||
updater.stop() | ||
time.sleep(2) | ||
assert not updater.is_alive() | ||
|
||
|
||
def test_renewal(config): | ||
KrbCommand.kdestroy(config) | ||
ticket = KrbTicket.init_by_config(config) | ||
starting = ticket.starting | ||
expires = ticket.expires | ||
updater = ticket.updater(interval=1) | ||
updater.start() | ||
time.sleep(2) | ||
updater.stop() | ||
assert ticket.starting > starting | ||
assert ticket.expires > expires |