{"id":13509156,"url":"https://github.com/pspdfkit-labs/bypass","last_synced_at":"2026-10-19T17:46:17.208Z","repository":{"id":41441292,"uuid":"42600815","full_name":"PSPDFKit-labs/bypass","owner":"PSPDFKit-labs","description":"Bypass provides a quick way to create a custom plug that can be put in place instead of an actual HTTP server to return prebaked responses to client requests.","archived":false,"fork":false,"pushed_at":"2025-07-10T09:08:20.000Z","size":6675,"stargazers_count":1001,"open_issues_count":27,"forks_count":117,"subscribers_count":13,"default_branch":"master","last_synced_at":"2026-10-14T07:44:48.301Z","etag":null,"topics":["api-testing","elixir","http","https","mock","plug","test-server","testing"],"latest_commit_sha":null,"homepage":"https://hex.pm/packages/bypass","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PSPDFKit-labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2015-09-16T16:52:16.000Z","updated_at":"2026-09-03T07:37:19.000Z","dependencies_parsed_at":"2024-05-01T17:21:13.450Z","dependency_job_id":"351a35c7-8816-4252-83ef-9fb93d93eba9","html_url":"https://github.com/PSPDFKit-labs/bypass","commit_stats":{"total_commits":154,"total_committers":35,"mean_commits":4.4,"dds":0.7142857142857143,"last_synced_commit":"64365047ea58d2a45eed43b44b186a09d726f3aa"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/PSPDFKit-labs/bypass","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PSPDFKit-labs%2Fbypass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PSPDFKit-labs%2Fbypass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PSPDFKit-labs%2Fbypass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PSPDFKit-labs%2Fbypass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PSPDFKit-labs","download_url":"https://codeload.github.com/PSPDFKit-labs/bypass/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PSPDFKit-labs%2Fbypass/sbom","scorecard":{"id":107062,"data":{"date":"2025-08-11","repo":{"name":"github.com/PSPDFKit-labs/bypass","commit":"0a47472667340ed7d3b1250751408c44c6f9a7d7"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.1,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: topLevel 'contents' permission set to 'read': .github/workflows/elixir.yml:10","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":6,"reason":"dependency not pinned by hash detected -- score normalized to 6","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/elixir.yml:97: update your workflow using https://app.stepsecurity.io/secureworkflow/PSPDFKit-labs/bypass/elixir.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/elixir.yml:104: update your workflow using https://app.stepsecurity.io/secureworkflow/PSPDFKit-labs/bypass/elixir.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   1 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":4,"reason":"Found 10/21 approved changesets -- score normalized to 4","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 23 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T11:17:50.646Z","repository_id":41441292,"created_at":"2025-08-15T11:17:50.646Z","updated_at":"2025-08-15T11:17:50.646Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":344872684,"owners_count":38363805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-10-03T21:59:58.778Z","status":"online","status_checked_at":"2026-10-19T02:00:06.414Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-testing","elixir","http","https","mock","plug","test-server","testing"],"created_at":"2024-08-01T02:01:03.751Z","updated_at":"2026-10-19T17:46:16.928Z","avatar_url":"https://github.com/PSPDFKit-labs.png","language":"Elixir","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"# Bypass\n\n\u003c!-- MDOC !--\u003e\n\n[![Build Status](https://github.com/PSPDFKit-labs/bypass/actions/workflows/elixir.yml/badge.svg?branch=master)](https://github.com/PSPDFKit-labs/bypass/actions)\n[![Module Version](https://img.shields.io/hexpm/v/bypass.svg)](https://hex.pm/packages/bypass)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/bypass/)\n[![Total Download](https://img.shields.io/hexpm/dt/bypass.svg)](https://hex.pm/packages/bypass)\n[![License](https://img.shields.io/hexpm/l/bypass.svg)](https://github.com/PSPDFKit-labs/bypass/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/PSPDFKit-labs/bypass.svg)](https://github.com/PSPDFKit-labs/bypass/commits/master)\n\n\n`Bypass` provides a quick way to create a custom plug that can be put in place\ninstead of an actual HTTP server to return prebaked responses to client\nrequests. This is most useful in tests, when you want to create a mock HTTP\nserver and test how your HTTP client handles different types of responses from\nthe server.\n\nBypass supports Elixir 1.10 and OTP 21 and up. It works with Cowboy 2.\n\n## Usage\n\nTo use Bypass in a test case, open a connection and use its port to connect your\nclient to it.\n\nIf you want to test what happens when the HTTP server goes down, use\n`Bypass.down/1` to close the TCP socket and `Bypass.up/1` to start listening on\nthe same port again. Both functions block until the socket updates its state.\n\n### Expect Functions\n\nYou can take any of the following approaches:\n\n* `expect/2` or `expect_once/2` to install a generic function that all calls to\n  bypass will use\n* `expect/4` and/or `expect_once/4` to install specific routes (method and path)\n* `stub/4` to install specific routes without expectations\n* a combination of the above, where the routes will be used first, and then the\n  generic version will be used as default\n\n### Example\n\nIn the following example `TwitterClient.start_link()` takes the endpoint URL as\nits argument allowing us to make sure it will connect to the running instance of\nBypass.\n\n```elixir\ndefmodule TwitterClientTest do\n  use ExUnit.Case, async: true\n\n  setup do\n    bypass = Bypass.open()\n    {:ok, bypass: bypass}\n  end\n\n  test \"client can handle an error response\", %{bypass: bypass} do\n    Bypass.expect_once(bypass, \"POST\", \"/1.1/statuses/update.json\", fn conn -\u003e\n      Plug.Conn.resp(conn, 429, ~s\u003c{\"errors\": [{\"code\": 88, \"message\": \"Rate limit exceeded\"}]}\u003e)\n    end)\n\n    {:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))\n    assert {:error, :rate_limited} == TwitterClient.post_tweet(client, \"Elixir is awesome!\")\n  end\n\n  test \"client can recover from server downtime\", %{bypass: bypass} do\n    Bypass.expect(bypass, fn conn -\u003e\n      # We don't care about `request_path` or `method` for this test.\n      Plug.Conn.resp(conn, 200, \"\")\n    end)\n\n    {:ok, client} = TwitterClient.start_link(url: endpoint_url(bypass.port))\n\n    assert :ok == TwitterClient.post_tweet(client, \"Elixir is awesome!\")\n\n    # Blocks until the TCP socket is closed.\n    Bypass.down(bypass)\n\n    assert {:error, :noconnect} == TwitterClient.post_tweet(client, \"Elixir is awesome!\")\n\n    Bypass.up(bypass)\n\n    # When testing a real client that is using e.g. https://github.com/fishcakez/connection\n    # with https://github.com/ferd/backoff to handle reconnecting, we'd have to loop for\n    # a while until the client has reconnected.\n\n    assert :ok == TwitterClient.post_tweet(client, \"Elixir is awesome!\")\n  end\n\n  defp endpoint_url(port), do: \"http://localhost:#{port}/\"\nend\n```\n\nThat's all you need to do. Bypass automatically sets up an `on_exit` hook to\nclose its socket when the test finishes running.\n\nMultiple concurrent Bypass instances are supported, all will have a different\nunique port.  Concurrent requests are also supported on the same instance.\n\n\u003e Note: `Bypass.open/0` **must not** be called in a `setup_all` blocks due to\n\u003e the way Bypass verifies the expectations at the end of each test.\n\n## How to use with ESpec\n\nWhile Bypass primarily targets ExUnit, the official Elixir builtin test\nframework, it can also be used with [ESpec](https://hex.pm/packages/espec). The\ntest configuration is basically the same, there are only two differences:\n\n1. In your Mix config file, you must declare which test framework Bypass is\n   being used with (defaults to `:ex_unit`). This simply disables the automatic\n   integration with some hooks provided by `ExUnit`.\n\n   ```elixir\n   config :bypass, test_framework: :espec\n   ```\n\n2. In your specs, you must explicitly verify the declared expectations. You can\n   do it in the `finally` block.\n\n   ```elixir\n   defmodule TwitterClientSpec do\n     use ESpec, async: true\n\n     before do\n       bypass = Bypass.open()\n       {:shared, bypass: bypass}\n     end\n\n     finally do\n       Bypass.verify_expectations!(shared.bypass)\n     end\n\n     specify \"the client can handle an error response\" do\n       Bypass.expect_once(shared.bypass, \"POST\", \"/1.1/statuses/update.json\", fn conn -\u003e\n         Plug.Conn.resp(conn, 429, ~s\u003c{\"errors\": [{\"code\": 88, \"message\": \"Rate limit exceeded\"}]}\u003e)\n       end)\n\n       {:ok, client} = TwitterClient.start_link(url: endpoint_url(shared.bypass.port))\n       assert {:error, :rate_limited} == TwitterClient.post_tweet(client, \"Elixir is awesome!\")\n     end\n\n     defp endpoint_url(port), do: \"http://localhost:#{port}/\"\n   end\n   ```\n\n## Configuration options\n\nSet `:enable_debug_log` to `true` in the application environment to make Bypass\nlog what it's doing:\n\n```elixir\nconfig :bypass, enable_debug_log: true\n```\n\n\u003c!-- MDOC !--\u003e\n\n## Installation\n\nAdd `:bypass` to your list of dependencies in mix.exs:\n\n```elixir\ndef deps do\n  [\n    {:bypass, \"~\u003e 2.1\", only: :test}\n  ]\nend\n```\n\nWe do not recommended adding `:bypass` to the list of applications in your\n`mix.exs`.\n\n## License\n\nThis software is licensed under [the MIT license](LICENSE).\n\n## About\n\n\u003ca href=\"https://nutrient.io/\"\u003e\n  \u003cimg src=\"https://avatars2.githubusercontent.com/u/1527679?v=3\u0026s=200\" height=\"80\" /\u003e\n\u003c/a\u003e\n\nThis project is maintained and funded by [Nutrient](https://nutrient.io/).\n\nPlease ensure [you signed our\nCLA](https://www.nutrient.io/guides/web/miscellaneous/contributing/) so we\ncan accept your contributions.\n\nSee [our other open source projects](https://github.com/PSPDFKit-labs), read\n[our blog](https://nutrient.io/blog/) or say hello on X\n([@nutrientdocs](https://x.com/nutrientdocs)).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpspdfkit-labs%2Fbypass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpspdfkit-labs%2Fbypass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpspdfkit-labs%2Fbypass/lists"}