Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into snyk-upgrade-9d0e4fa11752cb9a7152eef219111630
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeckmann committed Jan 30, 2021
2 parents bd77e18 + baee5ce commit f32b4fe
Show file tree
Hide file tree
Showing 24 changed files with 1,014 additions and 281 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -135,6 +135,10 @@ Run `ng build` to build the project. The build artifacts will be stored in the `

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Security Review Status: pre-audit

The code in this repository has not been audited.

## License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmailchain%2Fmailchain-web.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fmailchain%2Fmailchain-web?ref=badge_large)
511 changes: 388 additions & 123 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -29,23 +29,23 @@
"jquery": "^3.5.1",
"ngx-bootstrap": "^3.2.0",
"popper.js": "^1.16.1",
"rxjs": "~6.5.5",
"rxjs": "~6.6.0",
"semver": "^6.3.0",
"webpack": "^4.43.0",
"tslib": "^1.13.0",
"zone.js": "~0.10.3"
"webpack": "^4.44.0",
"zone.js": "^0.11.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.803.25",
"@angular/cli": "^8.3.22",
"@angular/cli": "^8.3.29",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@babel/compat-data": "~7.8.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^8.10.54",
"codelyzer": "^5.0.1",
"elliptic": "^6.5.2",
"elliptic": "^6.5.3",
"jasmine-core": "^3.5.0",
"jasmine-spec-reporter": "^5.0.2",
"karma": "^4.4.1",
Expand Down
63 changes: 37 additions & 26 deletions src/app/inbox/inbox-message/inbox-message.component.spec.ts
Expand Up @@ -10,13 +10,19 @@ import { of } from 'rxjs';
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service';
import { HttpClientModule } from '@angular/common/http';
import { NameserviceServiceStub } from 'src/app/services/mailchain/nameservice/nameservice.service.stub';
import { LocalStorageServerServiceStub } from 'src/app/services/helpers/local-storage-server/local-storage-server.service.stub';
import { LocalStorageServerService } from 'src/app/services/helpers/local-storage-server/local-storage-server.service';
import { ProtocolsService } from 'src/app/services/mailchain/protocols/protocols.service';
import { ProtocolsServiceStub } from 'src/app/services/mailchain/protocols/protocols.service.stub';

describe('InboxMessageComponent', () => {

let component: InboxMessageComponent;
let fixture: ComponentFixture<InboxMessageComponent>;
let mailchainService: MailchainService;
let nameserviceService: NameserviceService;
let localStorageServerService: LocalStorageServerService;
let protocolsService: ProtocolsService;

let mailchainTestService: MailchainTestService

Expand All @@ -33,7 +39,9 @@ describe('InboxMessageComponent', () => {
providers: [
HttpHelpersService,
MailchainService,
{ provide: ProtocolsService, useClass: ProtocolsServiceStub },
{ provide: NameserviceService, useClass: NameserviceServiceStub },
{ provide: LocalStorageServerService, useClass: LocalStorageServerServiceStub },
],
imports: [
ModalModule.forRoot(),
Expand All @@ -44,12 +52,15 @@ describe('InboxMessageComponent', () => {
})
.compileComponents();
mailchainTestService = TestBed.get(MailchainTestService);
protocolsService = TestBed.get(ProtocolsService);
localStorageServerService = TestBed.get(LocalStorageServerService);
nameserviceService = TestBed.get(NameserviceService);
mailchainService = TestBed.get(MailchainService);

}));

beforeEach(() => {

fixture = TestBed.createComponent(InboxMessageComponent);
component = fixture.componentInstance;

Expand Down Expand Up @@ -83,103 +94,103 @@ describe('InboxMessageComponent', () => {

describe('ngOnInit', () => {
describe('resolveNamesFromMessage', () => {
it('should resolve the To field when there is a resolvable name', () => {
it('should resolve the To field when there is a resolvable name', async () => {
component.currentMessage["headers"]["to"] = mcAddress1
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address1]).toEqual('myaddress.eth')
})
it('should NOT resolve the To field when there is NOT a resolvable name', () => {
it('should NOT resolve the To field when there is NOT a resolvable name', async () => {
component.currentMessage["headers"]["to"] = mcAddress2
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address2]).toEqual(undefined)
})
it('should resolve the From field when there is a resolvable name', () => {
it('should resolve the From field when there is a resolvable name', async () => {
component.currentMessage["headers"]["from"] = mcAddress1
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address1]).toEqual('myaddress.eth')
})
it('should NOT resolve the From field when there is NOT a resolvable name', () => {
it('should NOT resolve the From field when there is NOT a resolvable name', async () => {
component.currentMessage["headers"]["from"] = mcAddress2
component.ngOnInit()
await component.ngOnInit()
expect(component.messageNameRecords[address2]).toEqual(undefined)
})
});
});

describe('getViewForContentType', () => {
it('should call getViewForContentType when the content-type is plaintext ', () => {
it('should call getViewForContentType when the content-type is plaintext ', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})

it('should call getViewForContentType when the content-type is text/plain; charset="UTF-8"', () => {
it('should call getViewForContentType when the content-type is text/plain; charset="UTF-8"', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})

it('should call getViewForContentType when the content-type is unknown', () => {
it('should call getViewForContentType when the content-type is unknown', async () => {
spyOn(component, 'getViewForContentType')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.getViewForContentType).toHaveBeenCalled()
})
})

describe('addMessageText', () => {
it('should call addMessageText when the content-type is plaintext ', () => {
it('should call addMessageText when the content-type is plaintext ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).toHaveBeenCalled()
})

it('should NOT call addMessageText when the content-type is text/html; charset="UTF-8" ', () => {
it('should NOT call addMessageText when the content-type is text/html; charset="UTF-8" ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'text/html; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).not.toHaveBeenCalled()
})

it('should call addMessageText when the content-type is unknown ', () => {
it('should call addMessageText when the content-type is unknown ', async () => {
spyOn(component, 'addMessageText')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageText).toHaveBeenCalled()
})

})
describe('addMessageIframe', () => {
it('should NOT call addMessageIframe when the content-type is plaintext ', () => {
it('should NOT call addMessageIframe when the content-type is plaintext ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'text/plain; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).not.toHaveBeenCalled()
})

it('should call addMessageIframe when the content-type is text/html; charset="UTF-8" ', () => {
it('should call addMessageIframe when the content-type is text/html; charset="UTF-8" ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'text/html; charset="UTF-8"'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).toHaveBeenCalled()
})

it('should NOT call addMessageIframe when the content-type is unknown ', () => {
it('should NOT call addMessageIframe when the content-type is unknown ', async () => {
spyOn(component, 'addMessageIframe')

component.currentMessage["headers"]["content-type"] = 'unknown'
component.ngOnInit()
await component.ngOnInit()
expect(component.addMessageIframe).not.toHaveBeenCalled()
})

Expand Down
33 changes: 19 additions & 14 deletions src/app/inbox/inbox-message/inbox-message.component.ts
Expand Up @@ -2,6 +2,7 @@ import { Component, Input, Output, EventEmitter, OnInit, ViewEncapsulation } fro
import { InboundMail } from 'src/app/models/inbound-mail';
import { NameserviceService } from 'src/app/services/mailchain/nameservice/nameservice.service';
import { MailchainService } from 'src/app/services/mailchain/mailchain.service';
import { LocalStorageNameserviceService } from 'src/app/services/helpers/local-storage-nameservice/local-storage-nameservice.service';

@Component({
selector: '[inbox-message]',
Expand All @@ -22,6 +23,7 @@ export class InboxMessageComponent implements OnInit {
constructor(
private nameserviceService: NameserviceService,
private mailchainService: MailchainService,
private localStorageNameserviceService: LocalStorageNameserviceService,
) { }
/**
* Go back to the inbox-messages view
Expand All @@ -30,8 +32,8 @@ export class InboxMessageComponent implements OnInit {
this.goToInboxMessages.emit('');
}

ngOnInit() {
this.resolveNamesFromMessage()
async ngOnInit() {
await this.resolveNamesFromMessage()
this.getViewForContentType()
}

Expand All @@ -47,12 +49,13 @@ export class InboxMessageComponent implements OnInit {
* Sets the name corresponding to messageNameRecords
* @param addr address in format 0x1234...1234
*/
private resolveMessageNameRecords(addr) {
this.nameserviceService.resolveAddress(
private async resolveMessageNameRecords(addr) {
let obs = await this.nameserviceService.resolveAddress(
this.currentProtocol,
this.currentNetwork,
addr
).subscribe(res => {
)
obs.subscribe(res => {
if (res['ok']) {
this.messageNameRecords[addr] = res['body']['name']
}
Expand All @@ -63,15 +66,17 @@ export class InboxMessageComponent implements OnInit {
* resolveNamesFromMessages looks up the 'to' and 'from' name
* records according to the currentNetwork and currentProtocol
*/
private resolveNamesFromMessage() {
[
this.currentMessage["headers"]["to"],
this.currentMessage["headers"]["from"]
].forEach(element => {
let parsedAddr = this.parseAddressFromMailchain(element)
this.resolveMessageNameRecords(parsedAddr)
});

private async resolveNamesFromMessage() {
if (await this.localStorageNameserviceService.getCurrentNameserviceAddressEnabled() == "true") {

[
this.currentMessage["headers"]["to"],
this.currentMessage["headers"]["from"]
].forEach(async element => {
let parsedAddr = this.parseAddressFromMailchain(element)
await this.resolveMessageNameRecords(parsedAddr)
});
};
}

/**
Expand Down

0 comments on commit f32b4fe

Please sign in to comment.