Skip to content

Commit ff59282

Browse files
author
Zac Bowhay
committed
bug(): CORE-13939 - corellium-api getInstance() returned wrong project for instances
1 parent a019bf7 commit ff59282

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

src/corellium.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const { fetch, fetchApi, CorelliumError } = require('./util/fetch')
44
const Project = require('./project')
5+
const Instance = require('./instance')
56
const Team = require('./team')
67
const User = require('./user')
78
const Role = require('./role')
@@ -487,7 +488,6 @@ class Corellium {
487488
* await corellium.getInstance({ id: 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' })
488489
*/
489490
async getInstance (opts) {
490-
let lastError
491491
let id, throwIfNotOn
492492
if (typeof opts === 'string') {
493493
id = opts
@@ -496,24 +496,19 @@ class Corellium {
496496
({ id, throwIfNotOn = true } = opts)
497497
}
498498

499-
const projects = await this.projects()
500-
for (const project of projects) {
501-
try {
502-
const instance = await project.getInstance(id)
503-
if (throwIfNotOn && (instance.info.state !== 'on')) {
504-
throw new Error('The instance is not turned on')
505-
}
506-
return instance
507-
} catch (err) {
508-
if (!(err instanceof CorelliumError)) {
509-
throw err
510-
} else {
511-
lastError = err
512-
}
499+
try {
500+
const info = await fetchApi(this, `/instances/${id}`)
501+
const project = await this.getProject(info.project);
502+
const instance = new Instance(project, info);
503+
504+
if (throwIfNotOn && (instance.info.state !== 'on')) {
505+
throw new Error('The instance is not turned on')
513506
}
514-
}
515507

516-
throw lastError || new Error(`Could not retrieve instance! instanceId=${id}`)
508+
return instance
509+
} catch (err) {
510+
throw err;
511+
}
517512
}
518513
}
519514

src/project.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Project {
8383
*/
8484
async getInstance (id) {
8585
const info = await fetchApi(this, `/instances/${id}`)
86+
if (info.project !== this.id) {
87+
throw new Error('Instance does not belong to this project.');
88+
}
8689
return new Instance(this, info)
8790
}
8891

0 commit comments

Comments
 (0)