GithubHelp home page GithubHelp logo

URL Wildcards for hook matching about abao HOT 2 OPEN

ProLoser avatar ProLoser commented on June 2, 2024
URL Wildcards for hook matching

from abao.

Comments (2)

amarseillan-zz avatar amarseillan-zz commented on June 2, 2024

👍

from abao.

runejuhl avatar runejuhl commented on June 2, 2024

I did start implementing RegExp matching hooks at some point, but for some reason it turned out awkward -- as I remember it, it had something to do with the manner in which the test cases are added. Part of my idea was to have the tests do things in order and keep state in-between, so my tests would be able to e.g. authenticate -> GET / using session -> POST /password/change using session. My checkout is from late November, so I might be remembering wrong :)

Anyway, until this is implemented, what you can do is create a beforeEach or afterEach hook that checks the request path:

{beforeEach, after} = require 'hooks'

makeAuth = (username, password) ->
  return (new Buffer "#{username}:#{password}").toString 'base64'

username = 'runejuhl'
password = 'testpass'
auth = (new Buffer "#{username}:#{password}").toString 'base64'

# This endpoint generates a new password and returns it in the response. If we
# update the global variable `password`, it'll be used on subsequent requests.
after 'POST /user/{email}/password/generate -> 200', (test, done) ->
  password = test.response.body.password
  console.log 'new pass', password
  done()

beforeEach (test, done) ->
  console.log 'before', test.request.path
  console.log 'pass is', password

  # Don't use Basic auth for endpoints starting with /public
  if /^\/public\//.test(test.request.path)
    done()

  auth = makeAuth(username, password)
  test.request.headers['Authorization'] = "Basic #{auth}"
  done()

@ProLoser : For your case, you could match on /^\/browse\/. If you need more than a few tests, I'd put the regexes and accompanying functions in a map and run all functions that match the regex.

from abao.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.