Skip to content

Commit

Permalink
Merge branch 'ab/always_attach' into 'master'
Browse files Browse the repository at this point in the history
fix: Add new error IdentityAlreadyAttached

See merge request TankerHQ/sdk-react-native!37
  • Loading branch information
Alexandre BOSSARD committed May 19, 2021
2 parents c78ed6a + b63d965 commit e74ca02
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
33 changes: 32 additions & 1 deletion example/src/test_tanker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
getVerificationCode,
toggleSessionCertificates,
} from './admin';
import { InvalidArgument, InvalidVerification } from '@tanker/errors';
import {
InvalidArgument,
InvalidVerification,
IdentityAlreadyAttached,
} from '@tanker/errors';
import { createTanker, clearTankerDataDirs } from './tests';
import base64 from 'react-native-base64';

Expand Down Expand Up @@ -212,6 +216,33 @@ export const tankerTests = () => {
await tanker.verifyProvisionalIdentity({ email, verificationCode });
});

it('throws when attaching an already attached provisional identity', async () => {
await tanker.start(identity);
await tanker.registerIdentity({
passphrase: 'ice cold water',
});
const email = '[email protected]';
const provIdentity = await createProvisionalIdentity(email);
const result = await tanker.attachProvisionalIdentity(provIdentity);
expect(result.verificationMethod).deep.eq({ type: 'email', email });

const verificationCode = await getVerificationCode(email);
await tanker.verifyProvisionalIdentity({ email, verificationCode });

const other = await createTanker();
await other.start(await createIdentity());
await other.registerIdentity({ passphrase: 'otherpass' });
other.attachProvisionalIdentity(provIdentity);
expect(result.status).eq(Tanker.statuses.IDENTITY_VERIFICATION_NEEDED);
const verificationCode2 = await getVerificationCode(email);
await expect(
other.verifyProvisionalIdentity({
email,
verificationCode: verificationCode2,
})
).to.be.rejectedWith(IdentityAlreadyAttached);
});

it('can skip provisional identity verification', async () => {
const email = '[email protected]';
const provIdentity = await createProvisionalIdentity(email);
Expand Down
2 changes: 2 additions & 0 deletions ios/Utils+Private.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void rejectWithError(RCTPromiseRejectBlock _Nonnull reject, NSError* _Nonnull er
return @"DEVICE_REVOKED";
case TKRErrorUpgradeRequired:
return @"UPGRADE_REQUIRED";
case TKRErrorIdentityAlreadyAttached:
return @"IDENTITY_ALREADY_ATTACHED";
default:
return @"UNKNOWN_ERROR";
}
Expand Down
4 changes: 4 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DeviceRevoked,
Conflict,
UpgradeRequired,
IdentityAlreadyAttached,
TankerError,
} from '@tanker/errors';

Expand All @@ -33,6 +34,7 @@ export const errors = {
TankerError,
TooManyAttempts,
UpgradeRequired,
IdentityAlreadyAttached,
};

function translateException(e: any): never {
Expand Down Expand Up @@ -67,6 +69,8 @@ function translateException(e: any): never {
throw new Conflict(e.message);
case 'UPGRADE_REQUIRED':
throw new UpgradeRequired(e.message);
case 'IDENTITY_ALREADY_ATTACHED':
throw new IdentityAlreadyAttached(e.message);
default:
// This could be something else than a TankerException, do not wrap or convert to avoid losing information
throw e;
Expand Down

0 comments on commit e74ca02

Please sign in to comment.