diff --git a/API.md b/API.md index b1c2c9e..a122d34 100644 --- a/API.md +++ b/API.md @@ -5984,6 +5984,8 @@ new CIATriad(props: CIATriadProps) | **Name** | **Description** | | --- | --- | | hasHigherAvailabilty | *No description.* | +| hasHigherConfidentiality | *No description.* | +| hasHigherIntegrity | *No description.* | --- @@ -5999,6 +6001,30 @@ public hasHigherAvailabilty(availability: Availability): boolean --- +##### `hasHigherConfidentiality` + +```typescript +public hasHigherConfidentiality(confidentiality: Confidentiality): boolean +``` + +###### `confidentiality`Required + +- *Type:* Confidentiality + +--- + +##### `hasHigherIntegrity` + +```typescript +public hasHigherIntegrity(integrity: Integrity): boolean +``` + +###### `integrity`Required + +- *Type:* Integrity + +--- + #### Properties diff --git a/src/cia-triad.ts b/src/cia-triad.ts index 9330629..dcfa7b9 100644 --- a/src/cia-triad.ts +++ b/src/cia-triad.ts @@ -18,6 +18,36 @@ export class CIATriad { this.justification = props.justification; } + public hasHigherConfidentiality(confidentiality: Confidentiality): boolean { + const confidentialityRank: Record = { + [Confidentiality.PUBLIC]: 0, + [Confidentiality.INTERNAL]: 1, + [Confidentiality.RESTRICTED]: 2, + [Confidentiality.CONFIDENTIAL]: 3, + [Confidentiality.STRICTLY_CONFIDENTIAL]: 4, + }; + + const thisRank = confidentialityRank[this.confidentiality]; + const thatRank = confidentialityRank[confidentiality]; + + return thisRank > thatRank; + } + + public hasHigherIntegrity(integrity: Integrity): boolean { + const integrityRank: Record = { + [Integrity.ARCHIVE]: 0, + [Integrity.OPERATIONAL]: 1, + [Integrity.IMPORTANT]: 2, + [Integrity.CRITICAL]: 3, + [Integrity.MISSION_CRITICAL]: 4, + }; + + const thisRank = integrityRank[this.integrity]; + const thatRank = integrityRank[integrity]; + + return thisRank > thatRank; + } + public hasHigherAvailabilty(availability: Availability): boolean { const availabilityRank: Record = { [Availability.ARCHIVE]: 0, diff --git a/test/cia-triad.test.ts b/test/cia-triad.test.ts new file mode 100644 index 0000000..82a5b60 --- /dev/null +++ b/test/cia-triad.test.ts @@ -0,0 +1,43 @@ +import { Availability, CIATriad, Confidentiality, Integrity } from "../src"; + +test("hasHigherConfidentiality", () => { + const ciaTriad = new CIATriad({ + confidentiality: Confidentiality.INTERNAL, + availability: Availability.CRITICAL, + integrity: Integrity.IMPORTANT, + }); + + expect(ciaTriad.hasHigherConfidentiality(Confidentiality.PUBLIC)).toBe(true); + expect(ciaTriad.hasHigherConfidentiality(Confidentiality.INTERNAL)).toBe( + false + ); + expect( + ciaTriad.hasHigherConfidentiality(Confidentiality.STRICTLY_CONFIDENTIAL) + ).toBe(false); +}); + +test("hasHigherIntegrity", () => { + const ciaTriad = new CIATriad({ + confidentiality: Confidentiality.INTERNAL, + availability: Availability.CRITICAL, + integrity: Integrity.IMPORTANT, + }); + + expect(ciaTriad.hasHigherIntegrity(Integrity.ARCHIVE)).toBe(true); + expect(ciaTriad.hasHigherIntegrity(Integrity.IMPORTANT)).toBe(false); + expect(ciaTriad.hasHigherIntegrity(Integrity.MISSION_CRITICAL)).toBe(false); +}); + +test("hasHigherAvailabilty", () => { + const ciaTriad = new CIATriad({ + confidentiality: Confidentiality.INTERNAL, + availability: Availability.CRITICAL, + integrity: Integrity.IMPORTANT, + }); + + expect(ciaTriad.hasHigherAvailabilty(Availability.OPERATIONAL)).toBe(true); + expect(ciaTriad.hasHigherAvailabilty(Availability.CRITICAL)).toBe(false); + expect(ciaTriad.hasHigherAvailabilty(Availability.MISSION_CRITICAL)).toBe( + false + ); +});