Welcome to mirror list, hosted at ThFree Co, Russian Federation.

email_spec.rb « utils « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c81c2558f706b00ea45380e12ac1482d445202a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require 'fast_spec_helper'
require 'rspec-parameterized'

RSpec.describe Gitlab::Utils::Email, feature_category: :service_desk do
  using RSpec::Parameterized::TableSyntax

  describe '.obfuscated_email' do
    where(:input, :output) do
      'alex@gitlab.com'                                | 'al**@g*****.com'
      'alex@gl.co.uk'                                  | 'al**@g****.uk'
      'a@b.c'                                          | 'aa@b.c'
      'qqwweerrttyy@example.com'                       | 'qq**********@e******.com'
      'getsuperfancysupport@paywhatyouwant.accounting' | 'ge******************@p*************.accounting'
      'q@example.com'                                  | 'qq@e******.com'
      'q@w.'                                           | 'qq@w.'
      'a@b'                                            | 'aa@b'
      'trun"@"e@example.com'                           | 'tr******@e******.com'
      '@'                                              | '@'
      'n'                                              | 'n'
      'no mail'                                        | 'n******'
      'truncated@exa'                                  | 'tr*******@exa'
      ''                                               | ''
    end

    with_them do
      it { expect(described_class.obfuscated_email(input)).to eq(output) }
    end

    context 'when deform is active' do
      where(:input, :output) do
        'alex@gitlab.com'                                | 'al*****@g*****.c**'
        'alex@gl.co.uk'                                  | 'al*****@g*****.u**'
        'a@b.c'                                          | 'aa*****@b*****.c**'
        'qqwweerrttyy@example.com'                       | 'qq*****@e*****.c**'
        'getsuperfancysupport@paywhatyouwant.accounting' | 'ge*****@p*****.a**'
        'q@example.com'                                  | 'qq*****@e*****.c**'
        'q@w.'                                           | 'qq*****@w*****.'
        'a@b'                                            | 'aa*****@b**'
        'trun"@"e@example.com'                           | 'tr*****@e*****.c**'
        '@'                                              | '@'
        'no mail'                                        | 'n**'
        'n'                                              | 'n**'
        'truncated@exa'                                  | 'tr*****@e**'
        ''                                               | ''
      end

      with_them do
        it { expect(described_class.obfuscated_email(input, deform: true)).to eq(output) }
      end
    end
  end
end