Information Security Projects - Anonymous Message Board

Tell us what’s happening:

There are two problems I spent a lot time but can not fix it.
The first one is ValidationError. my “delete a Reply function code” and “Reporting a Reply function code” both have the same problem.
The second one is my " Reporting a Thread function code" works fine in browser and database, but can not pass the tests.

Could someone help me, thanks a lot in advance.

Your project link(s)

solution: https://replit.com/@codesumner/boilerplate-project-messageboard

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge Information:

Information Security Projects - Anonymous Message Board

If you look at the GET after the PUT you can see the objects returned do not contain the required properties.

The reported value of the thread_id will be changed to true.

PUT

Request URL: https://boilerplate-project-messageboard--codesumner.repl.co/api/threads/fcc_test
Payload: {"thread_id":"65495ca81d389aea04c0a8d0"}
Response: "reported"

GET:

Request URL: https://boilerplate-project-messageboard--codesumner.repl.co/api/threads/fcc_test
Response: [{
    "_id": "65495ca81d389aea04c0a8d0",
    "text": "fcc_test_thread",
    "replies": [
        {
            "text": "[deleted]",
            "created_on": "2023-11-06T21:37:45.000Z",
            "_id": "65495ca91d389aea04c0a8d3"
        }
    ],
    "board": "fcc_test",
    "created_on": "2023-11-06T21:37:44.000Z",
    "bumped_on": "2023-11-06T21:37:45.000Z",
    "__v": 0,
    "replycount": 1
},
 ...rest of the objects
]

Briefly looking at it, it looks like you are filtering out the property in the GET


Not sure about the replies one as I do not see a GET after that PUT.

About the second problem , everything seems ok, but still failed, I don’t know why.


Screen Shot 2023-11-06 at 3.57.33 PM

I thought GET filtered properties is for passing the test below,:

The ValidationError of delete a Reply is below, the problem is the same with Reporting a Reply, both can not save the updated data. here is my code:
app.delete(‘/api/replies/:board’, async (req, res) => {
let thread = await Thread.findById(req.body.thread_id)

if (thread) {
  let reply = thread.replies.find((reply) => {
    return reply.id === req.body.reply_id
  })
  if (reply.delete_password === req.body.delete_password) {
    reply.text = '[deleted]'
  } else {
    return res.send('incorrect password')
  }
  let updatedThread = await thread.save()
  if (updatedThread) {
    return res.send('success')
  }
} else {
  return res.send('Thread not found')
}

})
this.$__.validationError = new ValidationError(this);
^

ValidationError: Thread validation failed: replies.0.reported: Path reported is required., replies.0.created_on: Path created_on is required., replies.0.delete_password: Path delete_password is required.



when console.log(thread), we can see the the text has been changed to [deleted], but it can not save in database because the
ValidationError.

My bad, it doesn’t look like the tests are using the GET. If you change the res.json to res.send in the PUT handlers it should pass both PUT tests.

2 Likes

Thank you very much! you saved me.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.