<commit_before>require_relative "test_helper"

describe Identity::HerokuCookie do
  it "sets the Heroku cookie when appropriate" do
    app = middleware(-> (env) {
      env["heroku.cookie"] = { "nonce" => "1234" }
      [200, {}, {}]
    })
    _, headers, _ = app.call({})
    assert_includes headers["Set-Cookie"], "heroku_session=1;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=1234;"
  end

  it "deletes the Heroku cookie when appropriate" do
    app = middleware(-> (env) {
      [200, {}, {}]
    })
    _, headers, _ = app.call({})
    assert_includes headers["Set-Cookie"], "heroku_session=;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=;"
  end

  it "persists the Heroku cookie through a standard request" do
    cookie = cookies_for_nonce("1234")

    app = middleware(-> (env) {
      [200, {}, {}]
    })
    _, headers, _ = app.call({ "HTTP_COOKIE" => cookie })
    assert_includes headers["Set-Cookie"], "heroku_session=1;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=1234;"
  end

  private

  def cookies_for_nonce(nonce)
    app = middleware(-> (env) {
      env["heroku.cookie"] = { "nonce" => nonce }
      [200, {}, {}]
    })
    _, headers, _ = app.call({})

    # Rack will separate multiple `Set-Cookie` headers with a newline; grab the<commit_msg>Simplify this code a bit<commit_after>require_relative "test_helper"

describe Identity::HerokuCookie do
  it "sets the Heroku cookie when appropriate" do
    app = middleware(-> (env) {
      env["heroku.cookie"] = { "nonce" => "1234" }
      [200, {}, {}]
    })
    _, headers, _ = app.call({})
    assert_includes headers["Set-Cookie"], "heroku_session=1;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=1234;"
  end

  it "deletes the Heroku cookie when appropriate" do
    app = middleware(-> (env) {
      [200, {}, {}]
    })
    _, headers, _ = app.call({})
    assert_includes headers["Set-Cookie"], "heroku_session=;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=;"
  end

  it "persists the Heroku cookie through a standard request" do
    app = middleware(-> (env) {
      [200, {}, {}]
    })
    _, headers, _ = app.call({ "HTTP_COOKIE" => cookies_for_nonce("1234") })
    assert_includes headers["Set-Cookie"], "heroku_session=1;"
    assert_includes headers["Set-Cookie"], "heroku_session_nonce=1234;"
  end

  private

  def cookies_for_nonce(nonce)
    app = middleware(-> (env) {
      env["heroku.cookie"] = { "nonce" => nonce }
      [200, {}, {}]
    })
    _, headers, _ = app.call({})

    # Rack will separate multiple `Set-Cookie` headers with a newline; grab the
{'fraction_non_alphanumeric': 0.1609152288072018, 'fraction_numerical': 0.02250562640660165, 'mean_word_length': 3.4823529411764707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '329296', 'n_tokens_mistral': 929, 'n_tokens_neox': 871, 'n_words': 201}