<commit_before>require "test_helper"

class Admin::DashboardControllerTest < ActionController::TestCase

  context "When authentication is http_basic" do

    setup do
      Admin::DashboardController.send :include, Typus::Authentication::HttpBasic
    end

    should "return a 401 message when no credentials sent" do
      get :show
      assert_response 401
    end

    should "authenticate user with valid password" do
      @request.env['HTTP_AUTHORIZATION'] = 'Basic ' + Base64::encode64("admin:columbia")
      get :show
      assert_response :success
    end

    should "not authenticate user with invalid password" do
      @request.env['HTTP_AUTHORIZATION'] = 'Basic ' + Base64::encode64("admin:admin")
      get :show
      assert_response 401
    end

  end

  context "When authentication is none" do

    setup do
      Admin::DashboardController.send :include, Typus::Authentication::None
    end

    should "render dashboard" do
      get :show
      assert_response :success
    end

  end

  context "Not logged" do

    setup do
      @request.session[:typus_user_id] = nil
    end

    should "redirect to sign in when not signed in" do
      get :show
      assert_response :redirect<commit_msg>401 is :unauthorized<commit_after>require "test_helper"

class Admin::DashboardControllerTest < ActionController::TestCase

  context "When authentication is http_basic" do

    setup do
      Admin::DashboardController.send :include, Typus::Authentication::HttpBasic
    end

    should "return a 401 message when no credentials sent" do
      get :show
      assert_response :unauthorized
    end

    should "authenticate user with valid password" do
      @request.env['HTTP_AUTHORIZATION'] = 'Basic ' + Base64::encode64("admin:columbia")
      get :show
      assert_response :success
    end

    should "not authenticate user with invalid password" do
      @request.env['HTTP_AUTHORIZATION'] = 'Basic ' + Base64::encode64("admin:admin")
      get :show
      assert_response :unauthorized
    end

  end

  context "When authentication is none" do

    setup do
      Admin::DashboardController.send :include, Typus::Authentication::None
    end

    should "render dashboard" do
      get :show
      assert_response :success
    end

  end

  context "Not logged" do

    setup do
      @request.session[:typus_user_id] = nil
    end

    should "redirect to sign in when not signed in" do
      get :show
      assert_response :redirect
{'fraction_non_alphanumeric': 0.07580056749087961, 'fraction_numerical': 0.01256586947709769, 'mean_word_length': 3.1618887015177064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4817754', 'n_tokens_mistral': 721, 'n_tokens_neox': 672, 'n_words': 219}