Skip to content

Commit c89ab4d

Browse files
authored
fix: Merge pull request #6 from CedricProfessionnel/removeAuth
Remove authentification
2 parents ee84705 + aa856ee commit c89ab4d

File tree

4 files changed

+85
-66
lines changed

4 files changed

+85
-66
lines changed

cypress/integration/CognitoServer/basic.spec.js

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import CognitoDatasetManager from "../../../dist/CognitoDatasetManager.js"
22
import getAuthConfig from "./get-auth-config.js"
3+
import { Auth } from "aws-amplify"
34
var samplesDummies = {
45
name: "TestCypress",
56
interface: {
@@ -46,26 +47,32 @@ const dummyUser = {
4647
username: Cypress.env().COGNITO_USER_NAME,
4748
password: Cypress.env().COGNITO_USER_PASS,
4849
}
49-
Cypress.config("defaultCommandTimeout", 50000)
50-
describe("Cognito Server Tests", async () => {
51-
const authConfig = getAuthConfig()
52-
const dm = await new CognitoDatasetManager({ authConfig, user: dummyUser })
53-
54-
await it("Create the CognitoDatasetManager object", async () => {
50+
Cypress.config("defaultCommandTimeout", 100000)
51+
describe("Cognito Server Tests", () => {
52+
var authConfig
53+
var dm
54+
var user
55+
before("prepare test", async () => {
56+
authConfig = getAuthConfig()
57+
dm = await new CognitoDatasetManager({ authConfig })
58+
user = await Auth.signIn(dummyUser.username, dummyUser.password)
59+
})
60+
it("Create the CognitoDatasetManager object", async () => {
5561
var ready = await dm.isReady()
5662
expect(ready).to.equal(true)
63+
await Auth.signOut()
64+
ready = await dm.isReady()
65+
expect(ready).to.equal(false)
66+
user = await Auth.signIn(dummyUser.username, dummyUser.password)
5767
})
5868

59-
await it(
60-
"Made sure project " + nameProjectTest + " don't exist",
61-
async () => {
62-
await dm.removeProject(nameProjectTest)
63-
var projects = await dm.getProjects()
64-
expect(projects).to.not.include(nameProjectTest)
65-
}
66-
)
69+
it("Made sure project " + nameProjectTest + " don't exist", async () => {
70+
await dm.removeProject(nameProjectTest)
71+
var projects = await dm.getProjects()
72+
expect(projects).to.not.include(nameProjectTest)
73+
})
6774

68-
await it("Test create project", async () => {
75+
it("Test create project", async () => {
6976
var index = {
7077
name: samplesDummies.name,
7178
interface: samplesDummies.interface,
@@ -75,17 +82,17 @@ describe("Cognito Server Tests", async () => {
7582
expect(projects).to.include(nameProjectTest)
7683
})
7784

78-
await it("Test setProject", async () => {
85+
it("Test setProject", async () => {
7986
dm.setProject(nameProjectTest)
8087
expect(dm.projectName).to.equal(nameProjectTest)
8188
})
8289

83-
await it("Made sure no sample exist", async () => {
90+
it("Made sure no sample exist", async () => {
8491
var sampleList = await dm.getListSamples(false)
8592
expect(sampleList.length).to.equal(0)
8693
})
8794

88-
await it("Test addSamples", async () => {
95+
it("Test addSamples", async () => {
8996
await dm.addSamples(samplesDummies.samples)
9097
var annotationsList = await dm.getListSamples(false)
9198
expect(annotationsList.length).to.equal(2)
@@ -102,19 +109,19 @@ describe("Cognito Server Tests", async () => {
102109
expect(datalist.length).to.equal(1)
103110
})*/
104111

105-
await it("Test readJSONAllSmple", async () => {
112+
it("Test readJSONAllSmple", async () => {
106113
var json = await dm.readJSONAllSample(await dm.getListSamples(false))
107114
expect(json.length).to.equal(samplesDummies.samples.length)
108115
})
109116

110-
await it("Test getJSON", async () => {
117+
it("Test getJSON", async () => {
111118
var json = await dm.getJSON(
112119
nameProjectTest + "/samples/" + samplesDummies.samples[0]._id + ".json"
113120
)
114121
expect(json._id).to.equal(samplesDummies.samples[0]._id)
115122
})
116123

117-
await it("Test setJSON", async () => {
124+
it("Test setJSON", async () => {
118125
await dm.setJSON(
119126
nameProjectTest + "/samples/" + samplesDummies.samples[0]._id + ".json",
120127
samplesDummies.samples[1]
@@ -125,22 +132,22 @@ describe("Cognito Server Tests", async () => {
125132
expect(json._id).to.equal(samplesDummies.samples[1]._id)
126133
})
127134

128-
await it("Test getSamplesSummary", async () => {
135+
it("Test getSamplesSummary", async () => {
129136
var samplesSummary = await dm.getSamplesSummary()
130137
expect(samplesSummary[1].hasAnnotation).to.equal(false)
131138
})
132139

133-
await it("Test getSummary", async () => {
140+
it("Test getSummary", async () => {
134141
var summary = await dm.getSummary()
135142
expect(summary.samples[1].hasAnnotation).to.equal(false)
136143
})
137144

138-
await it("Test getDatasetProperty", async () => {
145+
it("Test getDatasetProperty", async () => {
139146
var datasetProperty = await dm.getDatasetProperty("name")
140147
expect(datasetProperty).to.equal(samplesDummies.name)
141148
})
142149

143-
await it("Test setDatasetProperty", async () => {
150+
it("Test setDatasetProperty", async () => {
144151
await dm.setDatasetProperty("samples", samplesDummies.samples)
145152
var summary = await dm.getSummary()
146153
expect(summary.samples[1].hasAnnotation).to.equal(true)
@@ -155,43 +162,43 @@ describe("Cognito Server Tests", async () => {
155162
expect(value.type).to.equal(undefined)
156163
})
157164

158-
await it("Test getSampleByIndex", async () => {
165+
it("Test getSampleByIndex", async () => {
159166
var sample = await dm.getSampleByIndex(0)
160167
expect(samplesDummies.samples[1]._id).to.include(sample._id)
161168
})
162169

163-
await it("Test getSample", async () => {
170+
it("Test getSample", async () => {
164171
var sample = await dm.getSample("shcscmhiv")
165172
expect(sample._id).to.equal("shcscmhiv")
166173
})
167174

168-
await it("Test setSample", async () => {
175+
it("Test setSample", async () => {
169176
await dm.setSample("adfaef", {})
170177
var annotation = await dm.getListSamples(nameProjectTest)
171178
expect(annotation.length).to.equal(3)
172179
})
173180

174-
await it("Test removeSamples", async () => {
181+
it("Test removeSamples", async () => {
175182
await dm.removeSamples(["adfaef"])
176183
var list = await dm.getListSamples(false, false)
177184
expect(list.length).to.equal(2)
178185
})
179186

180-
await it("Test setDataset", async () => {
187+
it("Test setDataset", async () => {
181188
samplesDummies.name = "TestCypress3"
182189
await dm.setDataset(samplesDummies)
183190
var projects = await dm.getProjects()
184191
expect(projects).to.include(samplesDummies.name)
185192
})
186193

187-
await it("Test getDataset", async () => {
194+
it("Test getDataset", async () => {
188195
samplesDummies.name = "TestCypress4"
189196
await dm.setDataset(samplesDummies)
190197
var dataset = await dm.getDataset()
191198
expect(dataset.name).to.include(samplesDummies.name)
192199
})
193200

194-
await it("Test removeProject", async () => {
201+
it("Test removeProject", async () => {
195202
await dm.removeProject(nameProjectTest)
196203
await dm.removeProject(nameProjectTest + "2")
197204
await dm.removeProject(nameProjectTest + "3")

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"ava": "^3.13.0",
2323
"babel-eslint": "^10.1.0",
2424
"browser-env": "^3.3.0",
25-
"cypress": "^5.5.0",
25+
"cypress": "^6.0.0",
2626
"dotenv": "^8.2.0",
2727
"dotenv-cli": "^4.0.0",
2828
"eslint": "^7.12.1",

src/CognitoDatasetManager.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventEmitter } from "events"
2-
import Amplify, { Auth, Storage } from "aws-amplify"
2+
import Amplify, { Storage, Auth } from "aws-amplify"
33
import seamlessImmutable from "seamless-immutable"
44
const { from: seamless } = seamlessImmutable
55

@@ -9,7 +9,6 @@ class CognitoDatasetManager extends EventEmitter {
99
proxyUrl = "https://cors-anywhere.herokuapp.com/"
1010
constructor({
1111
authConfig,
12-
user,
1312
dataPrivacyLevel = "private",
1413
privateDataExpire = 24 * 60 * 60,
1514
} = {}) {
@@ -32,20 +31,17 @@ class CognitoDatasetManager extends EventEmitter {
3231
this.dataPrivacyLevel = dataPrivacyLevel
3332

3433
Amplify.configure(this.authConfig)
35-
36-
this.cognitoSetUp = Auth.signIn(user.username, user.password)
3734
}
3835

3936
//Made sure the cognitoSetUp is finish and working
4037
isReady = async () => {
41-
await this.cognitoSetUp
38+
return await Auth.currentAuthenticatedUser()
4239
.then(() => {
43-
this.worked = true
40+
return true
4441
})
4542
.catch(() => {
46-
this.worked = false
43+
return false
4744
})
48-
return this.worked
4945
}
5046
/*fetchAFile = async (url) => {
5147
var proxyUrl = "https://cors-anywhere.herokuapp.com/"
@@ -160,7 +156,7 @@ class CognitoDatasetManager extends EventEmitter {
160156
}
161157
}
162158

163-
//Create an array with all the samples annotation json
159+
//Create an array with all the samples annotation json
164160
readJSONAllSample = async (listSamples) => {
165161
var json = new Array(listSamples.length)
166162

@@ -259,18 +255,17 @@ class CognitoDatasetManager extends EventEmitter {
259255
return url
260256
}*/
261257

262-
263258
//IMPORTANT index = the index of the array of samples :::: id = the property _id in a sample of the array
264259

265-
//get sample by index (the index follows aphabetical order in AWS)
266-
//IMPORTANT It can not follow the original order of samples due to AWS ways of listing files
260+
//get sample by index (the index follows aphabetical order in AWS)
261+
//IMPORTANT It can not follow the original order of samples due to AWS ways of listing files
267262
getSampleByIndex = async (index) => {
268263
const sampleRefId = this.ds.summary.samples[index]._id
269264
let sample = await this.getSample(sampleRefId)
270265
return sample
271266
}
272267

273-
//get sample by id
268+
//get sample by id
274269
getSample = async (sampleRefId) => {
275270
var json = await this.getJSON(
276271
this.projectName + "/samples/" + sampleRefId + ".json"
@@ -286,16 +281,16 @@ class CognitoDatasetManager extends EventEmitter {
286281
)
287282
}
288283

289-
// This is working but currently not used
284+
// This is working but currently not used
290285
// NOTE This function is really consumming so be careful
291-
// Put a file copy in AWS
286+
// Put a file copy in AWS
292287
addFile = async (name, blob) => {
293288
await Storage.put(this.projectName + "/assets/" + name, blob, {
294289
level: this.dataPrivacyLevel,
295290
}).catch((err) => console.log(err))
296291
}
297292

298-
//add a new samples to existing one or rewrite one already existing
293+
//add a new samples to existing one or rewrite one already existing
299294
addSamples = async (samples) => {
300295
await Promise.all(
301296
samples.map(async (obj) => {

yarn.lock

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,9 +2795,9 @@ aws-sign2@~0.7.0:
27952795
integrity sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=
27962796

27972797
aws4@^1.8.0:
2798-
version "1.10.1"
2799-
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.1.tgz#e1e82e4f3e999e2cfd61b161280d16a111f86428"
2800-
integrity sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==
2798+
version "1.11.0"
2799+
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
2800+
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
28012801

28022802
28032803
version "0.19.0"
@@ -3396,11 +3396,16 @@ combined-stream@^1.0.6, combined-stream@~1.0.6:
33963396
dependencies:
33973397
delayed-stream "~1.0.0"
33983398

3399-
commander@^4.0.1, commander@^4.1.1:
3399+
commander@^4.0.1:
34003400
version "4.1.1"
34013401
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
34023402
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==
34033403

3404+
commander@^5.1.0:
3405+
version "5.1.0"
3406+
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
3407+
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==
3408+
34043409
common-path-prefix@^3.0.0:
34053410
version "3.0.0"
34063411
resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0"
@@ -3595,10 +3600,10 @@ currently-unhandled@^0.4.1:
35953600
dependencies:
35963601
array-find-index "^1.0.1"
35973602

3598-
cypress@^5.5.0:
3599-
version "5.5.0"
3600-
resolved "https://registry.yarnpkg.com/cypress/-/cypress-5.5.0.tgz#1da0355794a43247f8a80cb7f505e83e1cf847cb"
3601-
integrity sha512-UHEiTca8AUTevbT2pWkHQlxoHtXmbq+h6Eiu/Mz8DqpNkF98zjTBLv/HFiKJUU5rQzp9EwSWtms33p5TWCJ8tQ==
3603+
cypress@^6.0.0:
3604+
version "6.0.0"
3605+
resolved "https://registry.yarnpkg.com/cypress/-/cypress-6.0.0.tgz#57050773c61e8fe1e5c9871cc034c616fcacded9"
3606+
integrity sha512-A/w9S15xGxX5UVeAQZacKBqaA0Uqlae9e5WMrehehAdFiLOZj08IgSVZOV8YqA9OH9Z0iBOnmsEkK3NNj43VrA==
36023607
dependencies:
36033608
"@cypress/listr-verbose-renderer" "^0.4.1"
36043609
"@cypress/request" "^2.88.5"
@@ -3612,7 +3617,7 @@ cypress@^5.5.0:
36123617
chalk "^4.1.0"
36133618
check-more-types "^2.24.0"
36143619
cli-table3 "~0.6.0"
3615-
commander "^4.1.1"
3620+
commander "^5.1.0"
36163621
common-tags "^1.8.0"
36173622
debug "^4.1.1"
36183623
eventemitter2 "^6.4.2"
@@ -3692,19 +3697,26 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
36923697
ms "2.0.0"
36933698

36943699
debug@^3.1.0:
3695-
version "3.2.6"
3696-
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
3697-
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
3700+
version "3.2.7"
3701+
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.7.tgz#72580b7e9145fb39b6676f9c5e5fb100b934179a"
3702+
integrity sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==
36983703
dependencies:
36993704
ms "^2.1.1"
37003705

3701-
debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0:
3706+
debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.2.0:
37023707
version "4.2.0"
37033708
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
37043709
integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==
37053710
dependencies:
37063711
ms "2.1.2"
37073712

3713+
debug@^4.1.1:
3714+
version "4.3.1"
3715+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
3716+
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
3717+
dependencies:
3718+
ms "2.1.2"
3719+
37083720
decamelize@^1.1.1, decamelize@^1.2.0:
37093721
version "1.2.0"
37103722
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
@@ -5518,11 +5530,11 @@ json5@^2.1.2:
55185530
minimist "^1.2.5"
55195531

55205532
jsonfile@^6.0.1:
5521-
version "6.0.1"
5522-
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.0.1.tgz#98966cba214378c8c84b82e085907b40bf614179"
5523-
integrity sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==
5533+
version "6.1.0"
5534+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
5535+
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
55245536
dependencies:
5525-
universalify "^1.0.0"
5537+
universalify "^2.0.0"
55265538
optionalDependencies:
55275539
graceful-fs "^4.1.6"
55285540

@@ -7945,6 +7957,11 @@ universalify@^1.0.0:
79457957
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
79467958
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
79477959

7960+
universalify@^2.0.0:
7961+
version "2.0.0"
7962+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
7963+
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
7964+
79487965
79497966
version "1.0.0"
79507967
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"

0 commit comments

Comments
 (0)