1
0

test_token.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import time
  4. def test_local_token(tokfile, pepper_cli, session_minion_id):
  5. '''Test local execution with token file'''
  6. ret = pepper_cli('-x', tokfile, '--make-token', '*', 'test.ping')
  7. assert ret[session_minion_id] is True
  8. def test_runner_token(tokfile, pepper_cli):
  9. '''Test runner execution with token file'''
  10. ret = pepper_cli('-x', tokfile, '--make-token', '--client', 'runner', 'test.metasyntactic')
  11. exps = [
  12. 'foo', 'bar', 'baz', 'qux', 'quux', 'quuz', 'corge', 'grault',
  13. 'garply', 'waldo', 'fred', 'plugh', 'xyzzy', 'thud'
  14. ]
  15. assert all(exp in ret for exp in exps)
  16. def test_token_expire(tokfile, pepper_cli):
  17. '''Test token override param'''
  18. now = time.time()
  19. pepper_cli('-x', tokfile, '--make-token',
  20. '--token-expire', '94670856',
  21. '*', 'test.ping')
  22. with open(tokfile, 'r') as tfile:
  23. token = json.load(tfile)
  24. diff = (now + float(94670856)) - token['expire']
  25. # Allow for 10-second window between request and master-side auth.
  26. assert diff < 10