|
| 1 | +import { grantsFactory, profileFactory } from '@linode/utilities'; |
1 | 2 | import { createLinodeRequestFactory } from '@linode/utilities'; |
2 | 3 | import { authenticate } from 'support/api/authentication'; |
| 4 | +import { mockGetUser } from 'support/intercepts/account'; |
3 | 5 | import { interceptCreateFirewall } from 'support/intercepts/firewalls'; |
| 6 | +import { |
| 7 | + mockGetProfile, |
| 8 | + mockGetProfileGrants, |
| 9 | +} from 'support/intercepts/profile'; |
4 | 10 | import { ui } from 'support/ui'; |
5 | 11 | import { cleanUp } from 'support/util/cleanup'; |
6 | 12 | import { createTestLinode } from 'support/util/linodes'; |
7 | 13 | import { randomLabel, randomString } from 'support/util/random'; |
8 | 14 | import { chooseRegion } from 'support/util/regions'; |
| 15 | + |
| 16 | +import { accountUserFactory } from 'src/factories'; |
9 | 17 | authenticate(); |
10 | 18 |
|
11 | 19 | describe('create firewall', () => { |
@@ -123,3 +131,65 @@ describe('create firewall', () => { |
123 | 131 | }); |
124 | 132 | }); |
125 | 133 | }); |
| 134 | + |
| 135 | +describe('restricted user cannot create firewall', () => { |
| 136 | + beforeEach(() => { |
| 137 | + cleanUp(['lke-clusters', 'linodes', 'firewalls']); |
| 138 | + const mockProfile = profileFactory.build({ |
| 139 | + restricted: true, |
| 140 | + username: randomLabel(), |
| 141 | + }); |
| 142 | + |
| 143 | + const mockUser = accountUserFactory.build({ |
| 144 | + restricted: true, |
| 145 | + user_type: 'default', |
| 146 | + username: mockProfile.username, |
| 147 | + }); |
| 148 | + |
| 149 | + const mockGrants = grantsFactory.build({ |
| 150 | + global: { |
| 151 | + add_firewalls: false, |
| 152 | + }, |
| 153 | + }); |
| 154 | + |
| 155 | + mockGetProfile(mockProfile); |
| 156 | + mockGetProfileGrants(mockGrants); |
| 157 | + mockGetUser(mockUser); |
| 158 | + }); |
| 159 | + |
| 160 | + /* |
| 161 | + * - Verifies that restricted user cannot create firewall on landing page |
| 162 | + */ |
| 163 | + it('confirms the create button is disabled on the Firewall Landing page', () => { |
| 164 | + cy.visitWithLogin('/firewalls'); |
| 165 | + ui.button |
| 166 | + .findByTitle('Create Firewall') |
| 167 | + .should('be.visible') |
| 168 | + .should('be.disabled'); |
| 169 | + }); |
| 170 | + |
| 171 | + /* |
| 172 | + * - Verifies that restricted user cannot create firewall in drawer |
| 173 | + */ |
| 174 | + it('confirms the Create Firewall button is disabled in create drawer', () => { |
| 175 | + cy.visitWithLogin('/firewalls/create'); |
| 176 | + |
| 177 | + ui.drawer |
| 178 | + .findByTitle('Create Firewall') |
| 179 | + .should('be.visible') |
| 180 | + .within(() => { |
| 181 | + cy.findByText( |
| 182 | + "You don't have permissions to create a new Firewall. Please contact an account administrator for details." |
| 183 | + ); |
| 184 | + ui.buttonGroup.findButtonByTitle('Create Firewall').scrollIntoView(); |
| 185 | + ui.buttonGroup |
| 186 | + .findButtonByTitle('Create Firewall') |
| 187 | + .should('be.visible') |
| 188 | + .should('be.disabled'); |
| 189 | + // all form inputs are disabled |
| 190 | + cy.get('input').each((input) => { |
| 191 | + cy.wrap(input).should('be.disabled'); |
| 192 | + }); |
| 193 | + }); |
| 194 | + }); |
| 195 | +}); |
0 commit comments