File tree 5 files changed +33
-2
lines changed
samples/webmvc-http-security/src
java/io/spring/sample/graphql
java/io/spring/sample/graphql
5 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ public class SalaryInput {
23
23
24
24
private BigDecimal newSalary ;
25
25
26
+ public SalaryInput (String employeeId , BigDecimal newSalary ) {
27
+ this .employeeId = employeeId ;
28
+ this .newSalary = newSalary ;
29
+ }
30
+
26
31
public String getEmployeeId () {
27
32
return employeeId ;
28
33
}
Original file line number Diff line number Diff line change 14
14
15
15
@ Configuration
16
16
@ EnableWebSecurity
17
- @ EnableGlobalMethodSecurity (prePostEnabled = true )
17
+ @ EnableGlobalMethodSecurity (prePostEnabled = true , securedEnabled = true )
18
18
public class SecurityConfig {
19
19
20
20
@ Bean
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ type Employee {
14
14
15
15
input UpdateSalaryInput {
16
16
employeeId : ID !
17
- salary : String !
17
+ newSalary : String !
18
18
}
19
19
type UpdateSalaryPayload {
20
20
success : Boolean !
Original file line number Diff line number Diff line change 8
8
import org .springframework .graphql .execution .ErrorType ;
9
9
import org .springframework .graphql .test .tester .WebGraphQlTester ;
10
10
11
+ import java .math .BigDecimal ;
12
+
11
13
import static org .assertj .core .api .Assertions .assertThat ;
12
14
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
13
15
@@ -72,6 +74,21 @@ void canNotQuerySalary() {
72
74
});
73
75
}
74
76
77
+ @ Test
78
+ void canNotMutationUpdateSalary () {
79
+ WebGraphQlTester tester = this .graphQlTester .mutate ().build ();
80
+ SalaryInput salaryInput = new SalaryInput ("1" , BigDecimal .valueOf (44 ));
81
+
82
+ tester .documentName ("updateSalary" )
83
+ .variable ("salaryInput" , salaryInput )
84
+ .execute ()
85
+ .errors ()
86
+ .satisfy (errors -> {
87
+ assertThat (errors ).hasSize (1 );
88
+ assertThat (errors .get (0 ).getErrorType ()).isEqualTo (ErrorType .UNAUTHORIZED );
89
+ });
90
+ }
91
+
75
92
@ Test
76
93
void canQuerySalaryAsAdmin () {
77
94
Original file line number Diff line number Diff line change
1
+ mutation updateSalary ($salaryInput : UpdateSalaryInput ! ) {
2
+ updateSalary (input : $salaryInput ) {
3
+ success
4
+ employee {
5
+ id
6
+ name
7
+ }
8
+ }
9
+ }
You can’t perform that action at this time.
0 commit comments