<commit_before>require './app/rapid_connect'

describe RapidConnect do
  def stringify_keys(hash)
    hash.reduce({}) { |a, (k, v)| a.merge(k.to_s => v) }
  end

  def reload_service
    json = @redis.hget('serviceproviders', identifier)
    RapidConnectService.new.from_json(json)
  end

  before :all do
    File.open('/tmp/rspec_organisations.json', 'w') { |f| f.write(JSON.generate ['Test Org Name', 'Another Test Org Name']) }
  end

  after :all do
    File.delete('/tmp/rspec_organisations.json')
  end

  before :each do
    @valid_shibboleth_headers = {
      'HTTP_SHIB_SESSION_ID' => 'abcd1234',
      'HTTP_PERSISTENT_ID' => 'https://idp.example.com!https://sp.example.com!0987zyxw',
      'HTTP_CN' => 'Test User',
      'HTTP_DISPLAYNAME' => 'Mr <NAME> User',
      'HTTP_GIVENNAME' => 'Test',
      'HTTP_SN' => 'User',
      'HTTP_MAIL' => '<EMAIL>',
      'HTTP_EPPN' => '<EMAIL>',
      'HTTP_AFFILIATION' => '<EMAIL>'
    }

    @valid_subject = {
      principal: @valid_shibboleth_headers['HTTP_PERSISTENT_ID'],
      cn: @valid_shibboleth_headers['HTTP_CN'],
      display_name: @valid_shibboleth_headers['HTTP_DISPLAYNAME'],
      given_name: @valid_shibboleth_headers['HTTP_GIVENNAME'],
      surname: @valid_shibboleth_headers['HTTP_SN'],
      mail: @valid_shibboleth_headers['HTTP_MAIL'],
      principal_name: @valid_shibboleth_headers['HTTP_EPPN'],
      scoped_affiliation: @valid_shibboleth_headers['HTTP_AFFILIATION']
    }

    @non_administrator = @valid_subject
      .merge(principal: 'https://idp.example.com!-!1234abcd')

    @redis =  Redis.new
  end

  after :each do
    flush_stores
  end

  def administrator
    @redis.hset('administrators', @valid_subject[:principal], { 'name' => @valid_subject[:cn], 'mail' => @valid_subject[:mail] }.to_json)
  end

  def exampleservice(opts = {})
    @redis.hset('serviceproviders', '1234abcd', opts.reverse_merge('name' => 'Our Web App', 'audience' => 'https://service.com', 'endpoint' => 'https://service.com/auth/jwt', 'secret' => '<KEY>').to_json)
  end

  def enableexampleservice(opts = {})
    exampleservice(opts)
    service_provider = JSON.parse(@redis.hget('serviceproviders', '1234abcd'))
    service_provider[:enabled] = true
    @redis.hset('serviceproviders', '1234abcd', service_provider.to_json)
  end

  describe '/' do
    it 'shows welcome erb' do
      get '/'
      expect(last_response).to be_ok
      expect(last_response.body).to contain('Welcome to AAF Rapid Connect')
    end
  end

  describe '/login' do
    it 'redirects to Shibboleth SP SSO on login request' do
      get '/login/1'
      expect(last_response).to be_redirect<commit_msg>Readd test case which was accidentally removed<commit_after>require './app/rapid_connect'

describe RapidConnect do
  def stringify_keys(hash)
    hash.reduce({}) { |a, (k, v)| a.merge(k.to_s => v) }
  end

  def reload_service
    json = @redis.hget('serviceproviders', identifier)
    RapidConnectService.new.from_json(json)
  end

  before :all do
    File.open('/tmp/rspec_organisations.json', 'w') { |f| f.write(JSON.generate ['Test Org Name', 'Another Test Org Name']) }
  end

  after :all do
    File.delete('/tmp/rspec_organisations.json')
  end

  before :each do
    @valid_shibboleth_headers = {
      'HTTP_SHIB_SESSION_ID' => 'abcd1234',
      'HTTP_PERSISTENT_ID' => 'https://idp.example.com!https://sp.example.com!0987zyxw',
      'HTTP_CN' => 'Test User',
      'HTTP_DISPLAYNAME' => 'Mr <NAME>',
      'HTTP_GIVENNAME' => 'Test',
      'HTTP_SN' => 'User',
      'HTTP_MAIL' => '<EMAIL>',
      'HTTP_EPPN' => '<EMAIL>',
      'HTTP_AFFILIATION' => '<EMAIL>'
    }

    @valid_subject = {
      principal: @valid_shibboleth_headers['HTTP_PERSISTENT_ID'],
      cn: @valid_shibboleth_headers['HTTP_CN'],
      display_name: @valid_shibboleth_headers['HTTP_DISPLAYNAME'],
      given_name: @valid_shibboleth_headers['HTTP_GIVENNAME'],
      surname: @valid_shibboleth_headers['HTTP_SN'],
      mail: @valid_shibboleth_headers['HTTP_MAIL'],
      principal_name: @valid_shibboleth_headers['HTTP_EPPN'],
      scoped_affiliation: @valid_shibboleth_headers['HTTP_AFFILIATION']
    }

    @non_administrator = @valid_subject
      .merge(principal: 'https://idp.example.com!-!1234abcd')

    @redis =  Redis.new
  end

  after :each do
    flush_stores
  end

  def administrator
    @redis.hset('administrators', @valid_subject[:principal], { 'name' => @valid_subject[:cn], 'mail' => @valid_subject[:mail] }.to_json)
  end

  def exampleservice(opts = {})
    @redis.hset('serviceproviders', '1234abcd', opts.reverse_merge('name' => 'Our Web App', 'audience' => 'https://service.com', 'endpoint' => 'https://service.com/auth/jwt', 'secret' => '<KEY>').to_json)
  end

  def enableexampleservice(opts = {})
    exampleservice(opts)
    service_provider = JSON.parse(@redis.hget('serviceproviders', '1234abcd'))
    service_provider[:enabled] = true
    @redis.hset('serviceproviders', '1234abcd', service_provider.to_json)
  end

  describe '/' do
    it 'shows welcome erb' do
      get '/'
      expect(last_response).to be_ok
      expect(last_response.body).to contain('Welcome to AAF Rapid Connect')
    end
  end

  describe '/developers' do
    it 'shows developers guide' do
      get '/developers'
      expect(last_response).to be_successful
      expect(last_response.body)
        .to contain('Integrating with AAF Rapid Connect')
    end
  end

  describe '/login' do
    it 'redirects to Shibboleth SP SSO on login request' do
      get '/login/1'
      expect(last_response).to be_redirect
{'fraction_non_alphanumeric': 0.14714337046352857, 'fraction_numerical': 0.008983111749910169, 'mean_word_length': 3.811581676750216, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 45, 'https://': 10, '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': '3298645', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1972, 'n_words': 359}