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

signature_badge_spec.js « components « commit « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d52ad2b43e20ae90070cefa5e8ac9bfa776fded3 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { GlBadge, GlLink, GlPopover } from '@gitlab/ui';
import { stubComponent, RENDER_ALL_SLOTS_TEMPLATE } from 'helpers/stub_component';
import SignatureBadge from '~/commit/components/signature_badge.vue';
import X509CertificateDetails from '~/commit/components/x509_certificate_details.vue';
import { typeConfig, statusConfig, verificationStatuses, signatureTypes } from '~/commit/constants';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import { helpPagePath } from '~/helpers/help_page_helper';
import { sshSignatureProp, gpgSignatureProp, x509SignatureProp } from '../mock_data';

describe('Commit signature', () => {
  let wrapper;

  const createComponent = (props = {}) => {
    wrapper = mountExtended(SignatureBadge, {
      propsData: {
        signature: {
          ...props,
        },
        stubs: {
          GlBadge,
          GlLink,
          X509CertificateDetails,
          GlPopover: stubComponent(GlPopover, { template: RENDER_ALL_SLOTS_TEMPLATE }),
        },
      },
    });
  };

  const signatureBadge = () => wrapper.findComponent(GlBadge);
  const signaturePopover = () => wrapper.findComponent(GlPopover);
  const signatureDescription = () => wrapper.findByTestId('signature-description');
  const signatureKeyLabel = () => wrapper.findByTestId('signature-key-label');
  const signatureKey = () => wrapper.findByTestId('signature-key');
  const helpLink = () => wrapper.findComponent(GlLink);
  const X509CertificateDetailsComponents = () => wrapper.findAllComponents(X509CertificateDetails);

  describe.each`
    signatureType          | verificationStatus
    ${signatureTypes.GPG}  | ${verificationStatuses.VERIFIED}
    ${signatureTypes.GPG}  | ${verificationStatuses.UNVERIFIED}
    ${signatureTypes.GPG}  | ${verificationStatuses.UNVERIFIED_KEY}
    ${signatureTypes.GPG}  | ${verificationStatuses.UNKNOWN_KEY}
    ${signatureTypes.GPG}  | ${verificationStatuses.OTHER_USER}
    ${signatureTypes.GPG}  | ${verificationStatuses.SAME_USER_DIFFERENT_EMAIL}
    ${signatureTypes.GPG}  | ${verificationStatuses.MULTIPLE_SIGNATURES}
    ${signatureTypes.X509} | ${verificationStatuses.VERIFIED}
    ${signatureTypes.SSH}  | ${verificationStatuses.VERIFIED}
    ${signatureTypes.SSH}  | ${verificationStatuses.REVOKED_KEY}
  `(
    'For a specified `$signatureType` and `$verificationStatus` it renders component correctly',
    ({ signatureType, verificationStatus }) => {
      beforeEach(() => {
        createComponent({ __typename: signatureType, verificationStatus });
      });
      it('renders correct badge class', () => {
        expect(signatureBadge().props('variant')).toBe(statusConfig[verificationStatus].variant);
      });
      it('renders badge text', () => {
        expect(signatureBadge().text()).toBe(statusConfig[verificationStatus].label);
      });
      it('renders  popover header text', () => {
        expect(signaturePopover().text()).toMatch(statusConfig[verificationStatus].title);
      });
      it('renders signature description', () => {
        expect(signatureDescription().text()).toBe(statusConfig[verificationStatus].description);
      });
      it('renders help link with correct path', () => {
        expect(helpLink().text()).toBe(typeConfig[signatureType].helpLink.label);
        expect(helpLink().attributes('href')).toBe(
          helpPagePath(typeConfig[signatureType].helpLink.path),
        );
      });
    },
  );

  describe('SSH signature', () => {
    beforeEach(() => {
      createComponent(sshSignatureProp);
    });

    it('renders key label', () => {
      expect(signatureKeyLabel().text()).toMatch(typeConfig[signatureTypes.SSH].keyLabel);
    });

    it('renders key signature', () => {
      expect(signatureKey().text()).toBe(sshSignatureProp.keyFingerprintSha256);
    });
  });

  describe('GPG signature', () => {
    beforeEach(() => {
      createComponent(gpgSignatureProp);
    });

    it('renders key label', () => {
      expect(signatureKeyLabel().text()).toMatch(typeConfig[signatureTypes.GPG].keyLabel);
    });

    it('renders key signature for GGP signature', () => {
      expect(signatureKey().text()).toBe(gpgSignatureProp.gpgKeyPrimaryKeyid);
    });
  });

  describe('X509 signature', () => {
    beforeEach(() => {
      createComponent(x509SignatureProp);
    });

    it('does not render key label', () => {
      expect(signatureKeyLabel().exists()).toBe(false);
    });

    it('renders X509 certificate details components', () => {
      expect(X509CertificateDetailsComponents()).toHaveLength(2);
    });

    it('passes correct props', () => {
      expect(X509CertificateDetailsComponents().at(0).props()).toStrictEqual({
        subject: x509SignatureProp.x509Certificate.subject,
        title: typeConfig[signatureTypes.X509].subjectTitle,
        subjectKeyIdentifier: wrapper.vm.getSubjectKeyIdentifierToDisplay(
          x509SignatureProp.x509Certificate.subjectKeyIdentifier,
        ),
      });
      expect(X509CertificateDetailsComponents().at(1).props()).toStrictEqual({
        subject: x509SignatureProp.x509Certificate.x509Issuer.subject,
        title: typeConfig[signatureTypes.X509].issuerTitle,
        subjectKeyIdentifier: wrapper.vm.getSubjectKeyIdentifierToDisplay(
          x509SignatureProp.x509Certificate.x509Issuer.subjectKeyIdentifier,
        ),
      });
    });
  });
});