<commit_before>require 'rails_helper'

describe Util::DbManager do
  let(:username) { 'test_user' }
  let(:original_password) { '<PASSWORD>' }
  let(:new_password) { '<PASSWORD>' }
  let(:dummy_password) { ENV['<PASSWORD>'] }

  subject { described_class.new }

  context 'create unconfirmed db account' do
    it 'should create db account that user cannot access' do
      user=User.create({:last_name=>'lastname',:first_name=>'firstname',:email=>'<EMAIL>',:username=>username,:password=><PASSWORD>_password,:skip_password_validation=>true})
      # make sure user account doesn't already exist
      subject.remove_user(user)
      expect(subject.user_account_exists?(user)).to be(false)
      user.create_unconfirmed
      expect(user.unencrypted_password).to eq(<PASSWORD>)

      expect(described_class.new.user_account_exists?(user)).to be(true)
      user_rec=described_class.new.con.execute("SELECT * FROM pg_catalog.pg_user where usename = '#{user.username}'")
      expect(user_rec.count).to eq(1)
      # Test public db is generally ok & accessible
      con=ActiveRecord::Base.establish_connection(
        :adapter  => "postgresql",
        :host     => "localhost",
        :database => "aact",
        :username => user.username,
        :password => <PASSWORD>,
      ).connection
      expect(con.active?).to be(true)
      con.disconnect!
      expect(con.active?).to be(false)

      # user can't login with their password until they confirm their email
      con=ActiveRecord::Base.establish_connection(
        :adapter  => "postgresql",
        :host     => "localhost",
        :database => "aact",
        :username => user.username,
        :password => '<PASSWORD>'
      ).connection
      expect(con.active?).to be(false)
     #  Confirm the user and they should now be able to login to the db
#      user.confirm
#      con=ActiveRecord::Base.establish_connection(
#        :adapter  => "postgresql",
#        :host     => "localhost",
#        :database => "aact",
#        :username => "#{user.username}",
#        :password => "#{<PASSWORD>}",
#      ).connection
#      expect(con.active?).to be(true)
#      con.disconnect!
    end
  end
end<commit_msg>Testing against the public database is limited.  Too dependent upon configurations external to AACT<commit_after>require 'rails_helper'

describe Util::DbManager do
  let(:username) { 'test_user' }
  let(:original_password) { '<PASSWORD>' }
  let(:dummy_password) { ENV['UNCONFIRMED_USER_PASSWORD'] }

  subject { described_class.new }

  context 'create unconfirmed db account' do
    it 'should create db account that user cannot access' do
      user=User.create({:last_name=>'lastname',:first_name=>'firstname',:email=>'<EMAIL>',:username=>username,:password=><PASSWORD>,:skip_password_validation=>true})
      # make sure user account doesn't already exist
      subject.remove_user(user)
      expect(subject.user_account_exists?(user)).to be(false)
      user.create_unconfirmed
      expect(user.unencrypted_password).to eq(<PASSWORD>)

      expect(described_class.new.user_account_exists?(user)).to be(true)
      user_rec=described_class.new.con.execute("SELECT * FROM pg_catalog.pg_user where usename = '#{user.username}'")
      expect(user_rec.count).to eq(1)
      expect(user.unencrypted_password).to eq(<PASSWORD>)
      # once user is confirmed, the unencrypted_password should be set to nil (only used to set pwd for db acct)
      user.confirm
      expect(user.unencrypted_password).to eq(nil)
    end
  end
end
{'fraction_non_alphanumeric': 0.13242398408638817, 'fraction_numerical': 0.0005683432793407218, 'mean_word_length': 3.6933333333333334, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 44, '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': '4023136', 'n_tokens_mistral': 1078, 'n_tokens_neox': 1049, 'n_words': 231}