File tree Expand file tree Collapse file tree 5 files changed +33
-2
lines changed
samples/webmvc-http-security/src
java/io/spring/sample/graphql
java/io/spring/sample/graphql Expand file tree Collapse file tree 5 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,11 @@ public class SalaryInput {
2323
2424 private BigDecimal newSalary ;
2525
26+ public SalaryInput (String employeeId , BigDecimal newSalary ) {
27+ this .employeeId = employeeId ;
28+ this .newSalary = newSalary ;
29+ }
30+
2631 public String getEmployeeId () {
2732 return employeeId ;
2833 }
Original file line number Diff line number Diff line change 1414
1515@ Configuration
1616@ EnableWebSecurity
17- @ EnableGlobalMethodSecurity (prePostEnabled = true )
17+ @ EnableGlobalMethodSecurity (prePostEnabled = true , securedEnabled = true )
1818public class SecurityConfig {
1919
2020 @ Bean
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ type Employee {
1414
1515input UpdateSalaryInput {
1616 employeeId : ID !
17- salary : String !
17+ newSalary : String !
1818}
1919type UpdateSalaryPayload {
2020 success : Boolean !
Original file line number Diff line number Diff line change 88import org .springframework .graphql .execution .ErrorType ;
99import org .springframework .graphql .test .tester .WebGraphQlTester ;
1010
11+ import java .math .BigDecimal ;
12+
1113import static org .assertj .core .api .Assertions .assertThat ;
1214import static org .assertj .core .api .Assertions .assertThatThrownBy ;
1315
@@ -72,6 +74,21 @@ void canNotQuerySalary() {
7274 });
7375 }
7476
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+
7592 @ Test
7693 void canQuerySalaryAsAdmin () {
7794
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