Skip to content

Commit

Permalink
Deletion operation for http interception dumps and interceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanishka Dilshan committed Dec 28, 2018
1 parent 62d13f4 commit b157973
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 13 deletions.
2 changes: 1 addition & 1 deletion routes/interception.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function processRequest(req, res, method, httpInterception) {

//STEP 1) save http dump
const originalHttpRequestDump = {
host: req.host,
host: req.hostname,
ip: req.ip,
protocol: req.protocol,
method: method,
Expand Down
48 changes: 42 additions & 6 deletions routes/interceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ router.get('/', (req, res) => {
.sort({ date: 'desc' })
.then(httpInterceptions => {
res.render('interceptions/index', {
httpInterceptionDumps : httpInterceptionDumps,
httpInterceptions : httpInterceptions,
httpInterceptionDumps: httpInterceptionDumps,
httpInterceptions: httpInterceptions,
indexView: true
});
})
Expand All @@ -35,8 +35,8 @@ router.get('/', (req, res) => {
});

//display only selected http reception
router.get('/:id', (req, res)=> {
HttpInterceptionDump.find({httpInterceptionId : req.params.id})
router.get('/:id', (req, res) => {
HttpInterceptionDump.find({ httpInterceptionId: req.params.id })
.sort({ date: 'desc' })
.then(httpInterceptionDumps => {
HttpInterception.find({})
Expand All @@ -45,8 +45,8 @@ router.get('/:id', (req, res)=> {
res.render('interceptions/index', {
interceptionUrl: envUtils.getHostName() + "/interception/" + req.params.id,
selectedInterceptionId: req.params.id,
httpInterceptionDumps : httpInterceptionDumps,
httpInterceptions : httpInterceptions
httpInterceptionDumps: httpInterceptionDumps,
httpInterceptions: httpInterceptions
});
})
.catch(err => {
Expand Down Expand Up @@ -100,4 +100,40 @@ router.post('/:id', (req, res) => {
})
})

//delete route for a selected http interception dump
router.get('/dump/:id/delete', (req, res) => {
HttpInterceptionDump.deleteOne({ _id: req.params.id })
.then(() => {
req.flash('warning_msg', 'Http Interception Dump Removed Successfully!');
res.redirect('/interceptions')
})
.catch(err => {
console.log(err);
res.send("Unable to delete")
})
});

//delete route for receptions
router.get('/:id/delete', (req, res) => {
//first find the reception to delete
HttpInterceptionDump.deleteMany({
httpInterceptionId: req.params.id
})
.then(() => {
HttpInterception.deleteOne({
_id: req.params.id
})
.then(() => {
req.flash('warning_msg', 'HttpInterception and Associated Interceptiondumps Removed Successfully!');
res.redirect('/interceptions');
})
.catch(err => {
res.send("Error when deleting HttpReception")
});
})
.catch(err => {
res.send("Error when deleting HttpDump")
});
});

module.exports = router;
19 changes: 15 additions & 4 deletions views/httpinterceptionsdumps/inspect.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" role="tab" data-toggle="tab" aria-controls="originalRequest" aria-selected="true"
href="#originalRequest"><span class="fas fa-angle-double-down" aria-hidden="true"></span> Original Request</a>
href="#originalRequest"><span class="fas fa-angle-double-down" aria-hidden="true"></span> Original
Request</a>
</li>
<li class="nav-item">
<a class="nav-link" role="tab" data-toggle="tab" aria-controls="forwadedRequest" aria-selected="false"
href="#forwadedRequest"><span class="fas fa-angle-double-up" aria-hidden="true"></span> Forwaded Request</a>
<a class="nav-link" role="tab" data-toggle="tab" aria-controls="forwadedRequest" aria-selected="false" href="#forwadedRequest"><span
class="fas fa-angle-double-up" aria-hidden="true"></span> Forwaded Request</a>
</li>
</ul>

Expand Down Expand Up @@ -146,9 +147,19 @@
<p class="h6 card-title">Response payload size : {{forwardedRequestDump.responseBody.length}} bytes</p>
</div>
</div>
{{/if}}
{{/if}}
<!-- End of the area for displaying forwaded http request-->
</div>
</div>
<hr />
<div class="d-inline-flex p-1">
<a href="/interceptions/dump/{{httpImterceptionDump._id}}/delete" class="btn btn-danger" style="margin:5px;" data-toggle="confirmation"
data-title="Are you sure?">
<span class="fas fa-trash" aria-hidden="true"></span> Delete
</a>

<a href="/receptions/save" class="btn btn-info" style="margin:5px;">
<span class="fas fa-save" aria-hidden="true"></span> Save
</a>
</div>
</div>
9 changes: 7 additions & 2 deletions views/interceptions/add.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Forward URL</span>
</div>
<input name="forwardUrl" class="form-control" value="" aria-describedby="basic-addon1"
placeholder="Target URL where the reqest to be forwarded" required>
<input name="forwardUrl" class="form-control" value="" aria-describedby="basic-addon1" placeholder="Target URL where the reqest to be forwarded"
required>
</div>

<div class="form-group">
Expand All @@ -45,6 +45,11 @@
<button type="submit" class="btn btn-primary">
<span class="fas fa-save" aria-hidden="true"></span> Update</button>

<a href="/receptions/{{receptionId}}/delete" class="btn btn-danger" style="margin:5px;" data-toggle="confirmation"
data-title="Are you sure?">
<span class="fas fa-trash" aria-hidden="true"></span> Delete
</a>

</form>
</div>

Expand Down

0 comments on commit b157973

Please sign in to comment.