From cc7154ad778e5a2810efc932135bbf46dd51d53c Mon Sep 17 00:00:00 2001 From: Lorhan Sohaky Date: Fri, 29 May 2020 15:42:14 -0300 Subject: [PATCH 1/4] Add TODO note --- frontend/src/services/nizkctf/gitlab.js | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/services/nizkctf/gitlab.js b/frontend/src/services/nizkctf/gitlab.js index 2c268a1..deb0bf0 100644 --- a/frontend/src/services/nizkctf/gitlab.js +++ b/frontend/src/services/nizkctf/gitlab.js @@ -86,6 +86,7 @@ export default class GitLab { }; } async listPullRequests(projectId, authorUsername, state) { + // TODO implements filter const response = await this.api.MergeRequests.all({ projectId, authorUsername, From e9ccd3bbdf14b6ab455ee385ca3943083071bef9 Mon Sep 17 00:00:00 2001 From: Lorhan Sohaky Date: Fri, 29 May 2020 15:43:31 -0300 Subject: [PATCH 2/4] Add filter paramether --- frontend/src/services/nizkctf/github.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/services/nizkctf/github.js b/frontend/src/services/nizkctf/github.js index 1e7fc4a..df6f2c4 100644 --- a/frontend/src/services/nizkctf/github.js +++ b/frontend/src/services/nizkctf/github.js @@ -78,12 +78,14 @@ export default class GitHub { }; } - async listPullRequests(repoName, username, state) { + async listPullRequests(repoName, state, filter, username = null) { const status = state === "opened" ? "open" : state; const { owner, repo } = repoNameHandler(repoName); - const query = `is:pr+repo:${owner}/${repo}+author:${username}+state:${status}`; + const query = filter + ? `${filter}+is:pr+repo:${owner}/${repo}+state:${status}` + : `is:pr+repo:${owner}/${repo}+author:${username}+state:${status}`; const { data } = await this.octokit.search.issuesAndPullRequests({ q: query From f6eb526bdb71d5b80a6ef59420cd1aa600df10db Mon Sep 17 00:00:00 2001 From: Lorhan Sohaky Date: Fri, 29 May 2020 15:44:05 -0300 Subject: [PATCH 3/4] Verify is there already a submissions in queue --- frontend/src/services/nizkctf/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/services/nizkctf/index.js b/frontend/src/services/nizkctf/index.js index 9a6d33c..5017c24 100644 --- a/frontend/src/services/nizkctf/index.js +++ b/frontend/src/services/nizkctf/index.js @@ -57,7 +57,13 @@ export default class NIZKCTF { const proof = await this._createProof(challenge, keys.privateKey); const path = getTeamPath(this.team.name); - const message = `Proof: found flag for ${challenge.id}`; + const message = `Proof: found flag for ${challenge.id} - ${path}`; + + const list = await this.api.listPullRequests(this.upstream, 'opened', `${message}:in:title`) + + if (list.length > 0) { + throw new Error("Your team has already sent this flag and it is in the bot's processing queue"); + } const newProof = Buffer.from(proof).toString("base64"); From 527611890f19dee0d451c10f23d76679d6270bad Mon Sep 17 00:00:00 2001 From: Lorhan Sohaky Date: Fri, 29 May 2020 15:44:25 -0300 Subject: [PATCH 4/4] Fix lint --- frontend/src/services/nizkctf/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/services/nizkctf/index.js b/frontend/src/services/nizkctf/index.js index 5017c24..27bb2a6 100644 --- a/frontend/src/services/nizkctf/index.js +++ b/frontend/src/services/nizkctf/index.js @@ -59,10 +59,16 @@ export default class NIZKCTF { const path = getTeamPath(this.team.name); const message = `Proof: found flag for ${challenge.id} - ${path}`; - const list = await this.api.listPullRequests(this.upstream, 'opened', `${message}:in:title`) + const list = await this.api.listPullRequests( + this.upstream, + "opened", + `${message}:in:title` + ); if (list.length > 0) { - throw new Error("Your team has already sent this flag and it is in the bot's processing queue"); + throw new Error( + "Your team has already sent this flag and it is in the bot's processing queue" + ); } const newProof = Buffer.from(proof).toString("base64");