Sha256: c0c1d562ae362dc1a73d20ab38b60a05d6fde2e67975fee3d4b86b55df320291

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe ::Doorkeeper::SecretStoring::Sha256Hash do
  subject { described_class }

  let(:instance) { double("instance") }

  let(:hash_function) do
    ->(input) { ::Digest::SHA256.hexdigest(input) }
  end

  describe "#transform_secret" do
    it "raises" do
      expect(subject.transform_secret("foo")).to eq hash_function.call("foo")
    end
  end

  describe "#restore_secret" do
    it "raises" do
      expect { subject.restore_secret(instance, :token) }.to raise_error(NotImplementedError)
    end
  end

  describe "#allows_restoring_secrets?" do
    it "does not allow it" do
      expect(subject.allows_restoring_secrets?).to eq false
    end
  end

  describe "validate_for" do
    it "allows for valid model" do
      expect(subject.validate_for(:application)).to eq true
      expect(subject.validate_for(:token)).to eq true
    end

    it "raises for invalid model" do
      expect { subject.validate_for(:wat) }.to raise_error(ArgumentError, /can not be used for wat/)
    end
  end

  describe "secret_matches?" do
    it "compares input with #transform_secret" do
      expect(subject.secret_matches?("input", "input")).to eq false
      expect(subject.secret_matches?("a", hash_function.call("a"))).to eq true
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
doorkeeper-mongodb-5.3.0 spec/lib/secret_storing/sha256_hash_spec.rb
doorkeeper-mongodb-5.2.3 spec/lib/secret_storing/sha256_hash_spec.rb
doorkeeper-sequel-2.4.0 spec/lib/secret_storing/sha256_hash_spec.rb
doorkeeper-mongodb-5.2.2 spec/lib/secret_storing/sha256_hash_spec.rb
doorkeeper-sequel-2.3.0 spec/lib/secret_storing/sha256_hash_spec.rb