<commit_before>require 'spec_helper'

describe "Authentications" do
  before(:each) do
    @session = Gsasl::Context.new
  end
  
  describe "CRAM-MD5" do
    before(:each) do
      @client = @session.create_client("CRAM-MD5")
      @server = @session.create_server("CRAM-MD5")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  describe "DIGEST-MD5" do
    before(:each) do
      @client = @session.create_client("DIGEST-MD5")
      @server = @session.create_server("DIGEST-MD5")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_SERVICE] = "imap"
      @client[Gsasl::GSASL_HOSTNAME] = "localhost"
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_SERVICE] = "imap"
      @client[Gsasl::GSASL_HOSTNAME] = "localhost"
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  describe "PLAIN" do
    before(:each) do
      @client = @session.create_client("PLAIN")
      @server = @session.create_server("PLAIN")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  after(:each) do
    @session.close
  end
end<commit_msg>added test for login auth method<commit_after>require 'spec_helper'

describe "Authentications" do
  before(:each) do
    @session = Gsasl::Context.new
  end
  
  describe "CRAM-MD5" do
    before(:each) do
      @client = @session.create_client("CRAM-MD5")
      @server = @session.create_server("CRAM-MD5")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  describe "DIGEST-MD5" do
    before(:each) do
      @client = @session.create_client("DIGEST-MD5")
      @server = @session.create_server("DIGEST-MD5")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "secret"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_SERVICE] = "imap"
      @client[Gsasl::GSASL_HOSTNAME] = "localhost"
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "test"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_SERVICE] = "imap"
      @client[Gsasl::GSASL_HOSTNAME] = "localhost"
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  describe "PLAIN" do
    before(:each) do
      @client = @session.create_client("PLAIN")
      @server = @session.create_server("PLAIN")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  describe "LOGIN" do
    before(:each) do
      @client = @session.create_client("LOGIN")
      @server = @session.create_server("LOGIN")
    end
    
    it "should be able to authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_true
    end
    
    it "should be possible to not authenticate correctly" do
      @server.callback do |property|
        if property == Gsasl::GSASL_PASSWORD
          if @server[Gsasl::GSASL_AUTHID] == "joe"
            @server[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
          end
          Gsasl::GSASL_OK
        end
      end
      
      @client[Gsasl::GSASL_AUTHID] = "joe"
      @client[Gsasl::GSASL_PASSWORD] = "<PASSWORD>"
      
      @client.authenticate(@server).should be_false
    end
    
    after(:each) do
      @client.close
      @server.close
    end
  end
  
  after(:each) do
    @session.close
  end
end
{'fraction_non_alphanumeric': 0.11735249292401481, 'fraction_numerical': 0.0013063357282821686, 'mean_word_length': 2.2485855728429986, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '1524969', 'n_tokens_mistral': 3328, 'n_tokens_neox': 3217, 'n_words': 589}