Sha256: 90989a321df7611f7775a296a0c0bb57722fc1084b5639ddfd21ac7c7788fe98

Contents?: true

Size: 1.22 KB

Versions: 22

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'test_plugin_helper'

module ForemanWebhooks
  class WebhookServiceTest < ActiveSupport::TestCase
    def setup
      User.current = users(:admin)
    end

    let(:webhook) { FactoryBot.create(:webhook) }
    let(:webhook_template) { FactoryBot.create(:webhook_template) }

    test 'password is saved encrypted when created' do
      Webhook.any_instance.expects(:encryption_key).at_least_once.returns('25d224dd383e92a7e0c82b8bf7c985e815f34cf5')
      webhook = Webhook.new(
        name: 'new12345', target_url: 'https://app.example.com',
        user: 'username', password: 'abcdef', events: 'host_created.event.foreman',
        webhook_template_id: webhook_template.id
      )
      as_admin do
        assert webhook.save!
      end
      assert_equal webhook.password, 'abcdef'
      refute_equal webhook.password_in_db, 'abcdef'
    end

    test 'password is saved encrypted when updated' do
      webhook.expects(:encryption_key).at_least_once.returns('25d224dd383e92a7e0c82b8bf7c985e815f34cf5')
      webhook.password = '123456'
      as_admin do
        assert webhook.save
      end
      assert_equal webhook.password, '123456'
      refute_equal webhook.password_in_db, '123456'
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
foreman_webhooks-4.0.0 test/models/webhook_test.rb
foreman_webhooks-3.2.3 test/models/webhook_test.rb
foreman_webhooks-3.2.2 test/models/webhook_test.rb
foreman_webhooks-3.1.1 test/models/webhook_test.rb
foreman_webhooks-3.2.1 test/models/webhook_test.rb
foreman_webhooks-3.2.0 test/models/webhook_test.rb
foreman_webhooks-3.1.0 test/models/webhook_test.rb
foreman_webhooks-3.0.5 test/models/webhook_test.rb
foreman_webhooks-2.0.3 test/models/webhook_test.rb
foreman_webhooks-3.0.4 test/models/webhook_test.rb
foreman_webhooks-2.0.2 test/models/webhook_test.rb
foreman_webhooks-3.0.3 test/models/webhook_test.rb
foreman_webhooks-3.0.2 test/models/webhook_test.rb
foreman_webhooks-3.0.1 test/models/webhook_test.rb
foreman_webhooks-2.0.1 test/models/webhook_test.rb
foreman_webhooks-3.0.0 test/models/webhook_test.rb
foreman_webhooks-2.0.0 test/models/webhook_test.rb
foreman_webhooks-1.1.0 test/models/webhook_test.rb
foreman_webhooks-1.0.0 test/models/webhook_test.rb
foreman_webhooks-0.0.3 test/models/webhook_test.rb