1

I'm running a flask api and I want to write some tavern tests for it. I use a basic base64 encode for the username and password that I send in the header when making requests which works fine on the API but I can't seem to get it to work for tavern.

stages:
  - name: login
    request:
      url: url
      method: GET
      headers:
        Authorization: Basic aGVsbG9zdGFja292ZXJmbG93
        accept: application/json
    response:

My api keeps refusing the authorization and without the Basic tag it doesn't recognize the format. Here is the flask authorization logic:

    try:
        api_key = base64.b64decode(api_key)
        username, password = api_key.split(':')
        if password == users[username]:
            user = User(username)
            return user
    except TypeError:
        current_app.login_manager.unauthorized()

All help/suggestions are appreciated

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Georges Lorré
  • 443
  • 3
  • 11
  • I'm assuming this is a dummy value for auth as decoding that returns `hellostackoverflow` and doesn't have a comma in it. Also this line is confusing me a little: `if password == users[username]:` – Tim Thompson Jul 09 '18 at 15:20
  • Did you get this working? – hookd Jul 30 '18 at 18:29

1 Answers1

0

There's documentation on this feature here: https://taverntesting.github.io/documentation#http-basic-auth

hookd
  • 465
  • 4
  • 7