mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-09 09:51:02 +01:00
36633bcb04
* Feature/SG-680 - Create Domain Verification Comp (#4283)
* domain-base.ts - added link to Architectural docs describing domain base class purpose
* SG-680 - (1) Created Org Domain API and observable based data store service (2) Created required response and request models
* SG-680 - Renaming org domain service abstractions to match existing convention
* SG-680 - (1) Updated getByOrgId method to return array of data to match back end + renamed it as such (2) Updated OrgDomainApiService get methods to update the OrgDomainService observables
* Two-factor-setup comp - change "tabbed-header" class to "page-header" to achieve visual consistency with other settings components.
* SG-680 - Refactor Org Domain API & domain services to conform to ADR 0013 - Avoid layered folder structure for request/response models (i.e., put models near "owner" services)
* SG-680 - Update Organization model to include a canManageDomainVerification check
* SG-680 - Created Domain Verification component and started scaffolding out HTML
* SG-680 - New OrgDomain state and API services need to be registered on jslib-services.module in order to be injectable into components for use (this is what maps abstractions to implementation for dependency injection)
* SG-680 - OrgDomainApiServiceAbstraction should be an abstract class
* SG-680 - Update OrgDomainApiService to use ListResponse and map into OrganizationDomainResponse properly
* SG-680 - Moved domain verification comp into subfolder to add clarity in folder structure
* SG-680 - Good start on Domain Add Edit Dialog
* SG-680 - Domain Add Edit Dialog - (1) Random generation of DNS TXT Record now working (2) DNS TXT Record Copyable (3) Additional translations added (4) Info callout added
* SG-680 - Domain Add Edit Dialog - (1) Added custom validator for domain name (2) Disable verify btn if form invalid
* SG-680 - Updated Domain Name custom validator to pass back error message in format the error.component.ts expected so it can be displayed without an untranslated error prefix of "invalidDomainName"
* Form-button - Added useful note regarding use of the bitFormButton directive and how it requires the use of the bitButton directive as well.
* SG-680 - OrgDomain.service - replace delete with splice as delete doesn't actually alter array. Duh.
* SG-680 - Domain verification progress - (1) Table layout + loading working for the most part (more translations needed (2) Add & edit opening dialog (3) Dialog first draft of save and verify
* SG-680 - DomainAddEditDialog - Unique domain name enforcement implemented
* SG-680 - Domain Name Custom Reactive forms validator refactor - swapped to regex to support proper domain format (which now enforces the requirement of a .com or similar)
* SG-680 - OrgDomainApi svc - must await send of delete call otherwise runs synchronously. Duh.
* SG-680 - Domain verification progress - (1) CopyDnsTxt added to state service (2) Refactored dialog to use async actions (3) Dialog form changes now mark form controls as touched for more responsive error handling
* SG-680 - Domain-add-edit-dialog - Confirmation required now for domain deletion
* SG-680 - Domain verification table options now supports removing domains with confirmation prompt
* Shared module - merge conflict resolution + removing unused imports so I can check this in.
* SG-680 - Adding missing translations
* SG-680 - Comment clean up + todo
* Revert "Shared module - merge conflict resolution + removing unused imports so I can check this in."
This reverts commit 98fe346e67
.
* SG-680 - DomainAddEditDialog - Replace bitAction with leveraging bitSubmit so that when users hit enter in a field the form gets submitted.
* SG-680 - Added httpStatusCode enum
* SG-680 - OrgDomainAPI - Verify endpoint now returns domain response model so upsert to sync obs state service
* SG-680 - Domain Verification comp - (1) Display last checked date (2) Verify first attempt in place (3) justify options content per design
* SG-680 - DomainAddEditDialog - Validation and error handling overhaul
* SG-680 - DomainAddEditDialog - (1) Autofocus domain name on new domain creation (2) Removed form.invalid == form disabled logic because of accessibility concerns
* SG-680 - OrgDomainResponse model refactor - back end is sending lower cased props
* SG-680 - OrgDomain service refactor - (1) Use proper abstraction for i18n svc (2) Don't make non-async methods async for no reason
* SG-680 - OrgDomainService - Added test suite
* SG-680 - Renaming httpStatusCode.enum to strip off .enum in attempt to pass eslint issue
* SG-680 - Renaming httpStatusCode enum file again to remove all capitalized letters to pass eslint rules.
* SG-680 - Updating HttpStatusCode import b/c auto import update missed it.
* SG-680 - DomainAddEditDialog - Don't show callout if domain is verified
* SG-680 - DomainVerificationComp - Add error handling to verify to handle case where domain isn't available
* SG-680 - OrgDomainApiSvc - svc should use abstractions in constructor
* SG-680 - OrgDomainApiSvc - added full test suite
* SG-680 - OrgDomainSvc test suite - fixing broken test
* SG-680 - Domain Verification Validation Scenario: show form control error when domain verification fails - (1) Enhanced bitSubmit to optionally allowDisabledFormSubmit (2) Enhanced bitInput to optionally allow showErrorsWhenDisabled + added new docs
* SG-680 - Adjusting location & name of the bitInput docs to be in the top level docs section to match historical consensus and existing pattern.
* SG-680 - Removed TODO for adding tests since I've already added tests.
* SG-680 - DomainAddEditDialog - Handle verify domain conflict exceptions just in case
* SG-680 - Adjusting location of Domain verification settings item in the organization settings menu to match figma.
* SG-680 - Removing unnecessary comment
* SG-680 - Domain Verification component - updated svg to not have alt text so it is treated as decorative by screen readers for accessibility.
* SG-680 - Fixing messages.json missing }
* SG-680 - DomainAddEditDialog - Hardcoding inputs to bit-dialog as component vars are not needed for dynamic anything right now.
* SG-680 - Dialog comment refactor
* SG-680 - OrgDomainSvc - comment and console log removals.
* SG-680 - Updating OrgDomain Service test suites to have better test titles.
* Defect/web org domain claiming bugfixes (#4458)
* SG-949 - OrgDomainVerification - Domain name validator now supports n levels of subdomains as well as top level domains.
* SG-955 - On domain verification error or failure, call to update the individual org domain item to get an updated last checked date on the client.
* SG-953 - In domain verification dialog edit, if verify called and failed, then must manually mark domain name as touched for errors to show up.
* SG-954 - Domain Verification edit dialog - Fixing delete button not having trash icon displayed + added i18n translation for title prop.
* SG-956 - Fixing domain claiming event logs so that they show up on the client (more to do as there are some events missing client & member)
* Form button directive comment update
* SG-977 - Event Log improvements: (1) Add new device type of server (2) Add EventSystemUser mapping to translated value. The end result is that both SCIM and Domain verification logs properly show server as the client and SCIM or Domain verification as the member.
* Add comment to clarify use of SCIM in EVENT_SYSTEM_USER_TO_TRANSLATION dict
* DeviceType.Server must be incremented to 22 b/c server master already has a DeviceType.SDK of 21.
* Add SDK w/ value of 21 to DeviceType to match master server
* Defect/web org domain claiming bugfixes the sequel (#4530)
* Update <bit-table> to latest standard so it works again (swap body from ng-container to ng-template)
* Input directive - showErrorsWhenDisabled case doesn't need to care if input isActive or not.
* SG-949 - Update domain name validator regex to prevent http://, https://, and www.
* SG-771 - Added claimed domain logic to web client (#4603)
* SG-771 / SG-772 / SG-743 - Add claimed domain logic which skips entry of Org SSO Id when an org has a claimed and verified domain to web, browser, and desktop.
* Fix lint errors by adding button types
---------
Co-authored-by: SmithThe4th <gsmith@bitwarden.com>
169 lines
6.3 KiB
TypeScript
169 lines
6.3 KiB
TypeScript
import { mock, mockReset } from "jest-mock-extended";
|
|
import { lastValueFrom } from "rxjs";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
import { OrganizationDomainResponse } from "@bitwarden/common/abstractions/organization-domain/responses/organization-domain.response";
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
import { OrgDomainService } from "@bitwarden/common/services/organization-domain/org-domain.service";
|
|
|
|
const mockedUnverifiedDomainServerResponse = {
|
|
creationDate: "2022-12-13T23:16:43.7066667Z",
|
|
domainName: "bacon.com",
|
|
id: "12eac4ea-9ed8-4dd4-85da-af6a017f9f97",
|
|
jobRunCount: 0,
|
|
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
|
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
|
object: "organizationDomain",
|
|
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
|
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
|
verifiedDate: null as any,
|
|
};
|
|
|
|
const mockedVerifiedDomainServerResponse = {
|
|
creationDate: "2022-12-13T23:16:43.7066667Z",
|
|
domainName: "cat.com",
|
|
id: "58715f70-8650-4a42-9d4a-af6a0188151b",
|
|
jobRunCount: 0,
|
|
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
|
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
|
object: "organizationDomain",
|
|
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
|
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
|
verifiedDate: "2022-12-13T23:16:43.7066667Z",
|
|
};
|
|
|
|
const mockedExtraDomainServerResponse = {
|
|
creationDate: "2022-12-13T23:16:43.7066667Z",
|
|
domainName: "dog.com",
|
|
id: "fac7cdb6-283e-4805-aa55-af6b016bf699",
|
|
jobRunCount: 0,
|
|
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
|
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
|
object: "organizationDomain",
|
|
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
|
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
|
verifiedDate: null as any,
|
|
};
|
|
|
|
const mockedUnverifiedOrgDomainResponse = new OrganizationDomainResponse(
|
|
mockedUnverifiedDomainServerResponse
|
|
);
|
|
const mockedVerifiedOrgDomainResponse = new OrganizationDomainResponse(
|
|
mockedVerifiedDomainServerResponse
|
|
);
|
|
|
|
const mockedExtraOrgDomainResponse = new OrganizationDomainResponse(
|
|
mockedExtraDomainServerResponse
|
|
);
|
|
|
|
describe("Org Domain Service", () => {
|
|
let orgDomainService: OrgDomainService;
|
|
|
|
const platformUtilService = mock<PlatformUtilsService>();
|
|
const i18nService = mock<I18nService>();
|
|
|
|
beforeEach(() => {
|
|
mockReset(platformUtilService);
|
|
mockReset(i18nService);
|
|
|
|
orgDomainService = new OrgDomainService(platformUtilService, i18nService);
|
|
});
|
|
|
|
it("instantiates", () => {
|
|
expect(orgDomainService).not.toBeFalsy();
|
|
});
|
|
|
|
it("orgDomains$ public observable exists and instantiates w/ empty array", () => {
|
|
expect(orgDomainService.orgDomains$).toBeDefined();
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual([]);
|
|
});
|
|
|
|
it("replace and clear work", () => {
|
|
const newOrgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
|
|
|
orgDomainService.replace(newOrgDomains);
|
|
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual(newOrgDomains);
|
|
|
|
orgDomainService.clearCache();
|
|
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toEqual([]);
|
|
});
|
|
|
|
it("get successfully retrieves org domain by id", () => {
|
|
const orgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
|
orgDomainService.replace(orgDomains);
|
|
|
|
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id)).toEqual(
|
|
mockedVerifiedOrgDomainResponse
|
|
);
|
|
|
|
expect(orgDomainService.get(mockedUnverifiedOrgDomainResponse.id)).toEqual(
|
|
mockedUnverifiedOrgDomainResponse
|
|
);
|
|
});
|
|
|
|
it("upsert both updates an existing org domain and adds a new one", () => {
|
|
const orgDomains = [mockedUnverifiedOrgDomainResponse, mockedVerifiedOrgDomainResponse];
|
|
orgDomainService.replace(orgDomains);
|
|
|
|
const changedOrgDomain = new OrganizationDomainResponse(mockedVerifiedDomainServerResponse);
|
|
changedOrgDomain.domainName = "changed domain name";
|
|
|
|
expect(mockedVerifiedOrgDomainResponse.domainName).not.toEqual(changedOrgDomain.domainName);
|
|
|
|
orgDomainService.upsert([changedOrgDomain]);
|
|
|
|
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id).domainName).toEqual(
|
|
changedOrgDomain.domainName
|
|
);
|
|
|
|
const newOrgDomain = new OrganizationDomainResponse({
|
|
creationDate: "2022-12-13T23:16:43.7066667Z",
|
|
domainName: "cat.com",
|
|
id: "magical-cat-id-number-999",
|
|
jobRunCount: 0,
|
|
lastCheckedDate: "2022-12-13T23:16:43.8033333Z",
|
|
nextRunDate: "2022-12-14T11:16:43.7066667Z",
|
|
object: "organizationDomain",
|
|
organizationId: "e4bffa5e-6602-4bc7-a83f-af55016566ef",
|
|
txt: "bw=eRBGgwJhZk0Kmpd8qPdSrrkSsTD006B+JgmMztk4XjDX",
|
|
verifiedDate: null as any,
|
|
});
|
|
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(2);
|
|
|
|
orgDomainService.upsert([newOrgDomain]);
|
|
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(3);
|
|
|
|
expect(orgDomainService.get(newOrgDomain.id)).toEqual(newOrgDomain);
|
|
});
|
|
|
|
it("delete successfully removes multiple org domains", () => {
|
|
const orgDomains = [
|
|
mockedUnverifiedOrgDomainResponse,
|
|
mockedVerifiedOrgDomainResponse,
|
|
mockedExtraOrgDomainResponse,
|
|
];
|
|
orgDomainService.replace(orgDomains);
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(3);
|
|
|
|
orgDomainService.delete([mockedUnverifiedOrgDomainResponse.id]);
|
|
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(2);
|
|
expect(orgDomainService.get(mockedUnverifiedOrgDomainResponse.id)).toEqual(undefined);
|
|
|
|
orgDomainService.delete([mockedVerifiedOrgDomainResponse.id, mockedExtraOrgDomainResponse.id]);
|
|
expect(lastValueFrom(orgDomainService.orgDomains$)).resolves.toHaveLength(0);
|
|
expect(orgDomainService.get(mockedVerifiedOrgDomainResponse.id)).toEqual(undefined);
|
|
expect(orgDomainService.get(mockedExtraOrgDomainResponse.id)).toEqual(undefined);
|
|
});
|
|
|
|
it("copyDnsTxt copies DNS TXT to clipboard and shows toast", () => {
|
|
orgDomainService.copyDnsTxt("fakeTxt");
|
|
expect(jest.spyOn(platformUtilService, "copyToClipboard")).toHaveBeenCalled();
|
|
expect(jest.spyOn(platformUtilService, "showToast")).toHaveBeenCalled();
|
|
});
|
|
});
|