Skip to content

Commit

Permalink
Add comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jun 28, 2022
1 parent cd1961b commit c1ef883
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
26 changes: 26 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5984,6 +5984,8 @@ new CIATriad(props: CIATriadProps)
| **Name** | **Description** |
| --- | --- |
| <code><a href="#cdktg.CIATriad.hasHigherAvailabilty">hasHigherAvailabilty</a></code> | *No description.* |
| <code><a href="#cdktg.CIATriad.hasHigherConfidentiality">hasHigherConfidentiality</a></code> | *No description.* |
| <code><a href="#cdktg.CIATriad.hasHigherIntegrity">hasHigherIntegrity</a></code> | *No description.* |

---

Expand All @@ -5999,6 +6001,30 @@ public hasHigherAvailabilty(availability: Availability): boolean

---

##### `hasHigherConfidentiality` <a name="hasHigherConfidentiality" id="cdktg.CIATriad.hasHigherConfidentiality"></a>

```typescript
public hasHigherConfidentiality(confidentiality: Confidentiality): boolean
```

###### `confidentiality`<sup>Required</sup> <a name="confidentiality" id="cdktg.CIATriad.hasHigherConfidentiality.parameter.confidentiality"></a>

- *Type:* <a href="#cdktg.Confidentiality">Confidentiality</a>

---

##### `hasHigherIntegrity` <a name="hasHigherIntegrity" id="cdktg.CIATriad.hasHigherIntegrity"></a>

```typescript
public hasHigherIntegrity(integrity: Integrity): boolean
```

###### `integrity`<sup>Required</sup> <a name="integrity" id="cdktg.CIATriad.hasHigherIntegrity.parameter.integrity"></a>

- *Type:* <a href="#cdktg.Integrity">Integrity</a>

---


#### Properties <a name="Properties" id="Properties"></a>

Expand Down
30 changes: 30 additions & 0 deletions src/cia-triad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ export class CIATriad {
this.justification = props.justification;
}

public hasHigherConfidentiality(confidentiality: Confidentiality): boolean {
const confidentialityRank: Record<Confidentiality, number> = {
[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, number> = {
[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, number> = {
[Availability.ARCHIVE]: 0,
Expand Down
43 changes: 43 additions & 0 deletions test/cia-triad.test.ts
Original file line number Diff line number Diff line change
@@ -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
);
});

0 comments on commit c1ef883

Please sign in to comment.