@@ -81,6 +81,51 @@ function ($notification, $channels) use ($ticket) {
81
81
);
82
82
}
83
83
84
+ /** @test */
85
+ public function can_create_a_ticket_with_js_injection (){
86
+ Notification::fake ();
87
+ $ admin = factory (Admin::class)->create ();
88
+ $ nonAdmin = factory (User::class)->create (["admin " => 0 ]);
89
+
90
+ $ response = $ this ->post ('api/tickets ' ,[
91
+ "requester " => [
92
+ "name " => "johndoe " ,
93
+
94
+ ],
95
+ "title " => "App <script>is not working</script> >>> " ,
96
+ "body " => "I can't log in into the application<script>alert(1)</script> " ,
97
+ "tags " => ["xef " ]
98
+ ],["token " => 'the-api-token ' ]);
99
+
100
+ $ response ->assertStatus ( Response::HTTP_CREATED );
101
+ $ response ->assertJson (["data " => ["id " => 1 ]]);
102
+
103
+ tap ( Ticket::first (), function ($ ticket ) use ($ admin ) {
104
+ tap ( Requester::first (), function ($ requester ) use ($ ticket ){
105
+ $ this ->assertEquals ($ requester ->name , "johndoe " );
106
+ $ this ->
assertEquals (
$ requester->
email ,
"[email protected] " );
107
+ $ this ->assertEquals ( $ ticket ->requester_id , $ requester ->id );
108
+ });
109
+ $ this ->assertEquals ( $ ticket ->title , "App is not working >>> " );
110
+ $ this ->assertEquals ( $ ticket ->body , "I can't log in into the applicationalert(1) " );
111
+ $ this ->assertTrue ( $ ticket ->tags ->pluck ('name ' )->contains ("xef " ) );
112
+ $ this ->assertEquals ( Ticket::STATUS_NEW , $ ticket ->status );
113
+
114
+ Notification::assertSentTo (
115
+ [$ admin ],
116
+ TicketCreated::class,
117
+ function ($ notification , $ channels ) use ($ ticket ) {
118
+ return $ notification ->ticket ->id === $ ticket ->id ;
119
+ }
120
+ );
121
+ });
122
+
123
+
124
+ Notification::assertNotSentTo (
125
+ [$ nonAdmin ], TicketCreated::class
126
+ );
127
+ }
128
+
84
129
/** @test */
85
130
public function requester_is_required (){
86
131
$ response = $ this ->post ('api/tickets ' ,$ this ->validParams ([
@@ -163,6 +208,25 @@ public function requester_can_comment_the_ticket(){
163
208
//TODO: assert notifications
164
209
}
165
210
211
+ /** @test */
212
+ public function requester_can_comment_the_ticket_with_js_injection (){
213
+ Notification::fake ();
214
+ $ ticket = factory (Ticket::class)->create ();
215
+ $ ticket ->comments ()->create (["body " => "first comment " , "new_status " => 1 ]);
216
+
217
+ $ response = $ this ->post ("api/tickets/ {$ ticket ->id }/comments " , [
218
+ "body " => "<script> this is a comment </script> "
219
+ ],["token " => 'the-api-token ' ]);
220
+
221
+ $ response ->assertStatus ( Response::HTTP_CREATED );
222
+ $ response ->assertJson (["data " => ["id " => 2 ]]);
223
+
224
+ $ this ->assertCount (2 , $ ticket ->comments );
225
+ $ this ->assertEquals ($ ticket ->comments [1 ]->body , " this is a comment " );
226
+
227
+ //TODO: assert notifications
228
+ }
229
+
166
230
/** @test */
167
231
public function commenting_a_closed_ticket_reopens_it (){
168
232
Notification::fake ();
0 commit comments