def test_auth_plugin_parse_auth_false(httpbin): class Plugin(AuthPlugin): auth_type = 'test-parse-false' auth_parse = False def get_auth(self, username=None, password=None): assert username is None assert password is None assert self.raw_auth == BASIC_AUTH_HEADER_VALUE return basic_auth(self.raw_auth) plugin_manager.register(Plugin) try: r = http( httpbin + BASIC_AUTH_URL, '--auth-type', Plugin.auth_type, '--auth', BASIC_AUTH_HEADER_VALUE, ) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
def test_auth_plugin_prompt_password_false(httpbin): class Plugin(AuthPlugin): auth_type = 'test-prompt-false' prompt_password = False def get_auth(self, username=None, password=None): assert self.raw_auth == USERNAME assert username == USERNAME assert password is None return basic_auth() plugin_manager.register(Plugin) try: r = http( httpbin + BASIC_AUTH_URL, '--auth-type', Plugin.auth_type, '--auth', USERNAME, ) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
def test_auth_plugin_require_auth_false_and_auth_provided(httpbin): class Plugin(AuthPlugin): auth_type = 'test-require-false-yet-provided' auth_require = False def get_auth(self, username=None, password=None): assert self.raw_auth == USERNAME + SEP_CREDENTIALS + PASSWORD assert username == USERNAME assert password == PASSWORD return basic_auth() plugin_manager.register(Plugin) try: r = http( httpbin + BASIC_AUTH_URL, '--auth-type', Plugin.auth_type, '--auth', USERNAME + SEP_CREDENTIALS + PASSWORD, ) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
def test_auth_plugin_require_auth_false(httpbin): class Plugin(AuthPlugin): auth_type = "test-require-false" auth_require = False def get_auth(self, username=None, password=None): assert self.raw_auth is None assert username is None assert password is None return basic_auth() plugin_manager.register(Plugin) try: r = http(httpbin + BASIC_AUTH_URL, "--auth-type", Plugin.auth_type) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
def test_auth_plugin_prompt_password_false(httpbin): class Plugin(AuthPlugin): auth_type = "test-prompt-false" prompt_password = False def get_auth(self, username=None, password=None): assert self.raw_auth == USERNAME assert username == USERNAME assert password is None return basic_auth() plugin_manager.register(Plugin) try: r = http(httpbin + BASIC_AUTH_URL, "--auth-type", Plugin.auth_type, "--auth", USERNAME) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
def test_auth_plugin_require_auth_false_and_auth_provided(httpbin): class Plugin(AuthPlugin): auth_type = "test-require-false-yet-provided" auth_require = False def get_auth(self, username=None, password=None): assert self.raw_auth == USERNAME + SEP_CREDENTIALS + PASSWORD assert username == USERNAME assert password == PASSWORD return basic_auth() plugin_manager.register(Plugin) try: r = http( httpbin + BASIC_AUTH_URL, "--auth-type", Plugin.auth_type, "--auth", USERNAME + SEP_CREDENTIALS + PASSWORD ) assert HTTP_OK in r assert r.json == AUTH_OK finally: plugin_manager.unregister(Plugin)
# -*- coding: utf-8 -*- """integration test for httpie_jwt_auth:JWTAuthPlugin""" import os from httpie.plugins import plugin_manager from httpie_jwt_auth import JWTAuthPlugin from .utils import http, HTTP_OK plugin_manager.register(JWTAuthPlugin) def test_required(httpbin): """$ http [url] --auth-type=jwt => --auth or JWT_AUTH_TOKEN required error""" try: r = http(httpbin.url + '/headers', '--auth-type', 'jwt') # TODO(hoatle): handle this # assert r.exit_status == 1 # assert '--auth or JWT_AUTH_TOKEN required error' in r.stdout or r.stderr # basically print error with the same behavior like: `--auth required error` except Exception as ex: assert '--auth or JWT_AUTH_TOKEN required error' in str(ex) def test_colon_character(httpbin): """ $ http [url] --auth-type=jwt --auth=abc: => the right Authorization request header with default token prefix (Bearer) This is compatible behavior with httpie-jwt-auth v0.2.1 and below """ r = http(httpbin.url + '/headers', '--auth-type', 'jwt', '--auth', 'abc:')