@@ -60,7 +60,37 @@ describe('Testing org put endpoint', () => {
60
60
expect ( err ) . to . be . undefined
61
61
} )
62
62
} )
63
- it ( 'Update made by non secretariat org to itself ONLY updates last_active field' , async ( ) => {
63
+ it ( 'Update made by a secretariat to another org does NOT update last_active field' , async ( ) => {
64
+ await chai . request ( app )
65
+ . put ( '/api/org/win_5' )
66
+ . set ( { ...constants . headers } )
67
+ . query ( params )
68
+ . send ( )
69
+ . then ( ( res , err ) => {
70
+ expect ( res . body . updated . last_active ) . to . be . undefined
71
+ expect ( res ) . to . have . status ( 200 )
72
+ expect ( err ) . to . be . undefined
73
+ } )
74
+ } )
75
+ it ( 'Update made by a secretariat to itself DOES update last_active field' , async ( ) => {
76
+ const now = Date . now ( )
77
+ await chai . request ( app )
78
+ . put ( '/api/org/mitre' )
79
+ . set ( { ...constants . headers } )
80
+ . query ( params )
81
+ . send ( )
82
+ . then ( ( res , err ) => {
83
+ expect ( res . body . updated . last_active ) . to . not . be . null
84
+ // Assert that that the last_active field was updated under 2 seconds ago
85
+ const lastActive = Date . parse ( res . body . updated . last_active )
86
+ const diff = Math . abs ( now - lastActive )
87
+ const withinTwoSeconds = diff < 2000
88
+ expect ( withinTwoSeconds ) . to . be . true
89
+ expect ( res ) . to . have . status ( 200 )
90
+ expect ( err ) . to . be . undefined
91
+ } )
92
+ } )
93
+ it ( 'Update made by non-secretariat org to itself ONLY updates last_active field' , async ( ) => {
64
94
const now = Date . now ( )
65
95
await chai . request ( app )
66
96
. put ( '/api/org/win_5' )
@@ -80,6 +110,54 @@ describe('Testing org put endpoint', () => {
80
110
expect ( err ) . to . be . undefined
81
111
} )
82
112
} )
113
+ it ( 'Request body ignored in update made by non-secretariat org to itself' , async ( ) => {
114
+ const requestBody = {
115
+ key1 : 'value1' ,
116
+ key2 : 'value2' ,
117
+ key3 : 'value3' ,
118
+ key4 : 'value4' ,
119
+ key5 : 'value5' ,
120
+ key6 : 'value6' ,
121
+ key7 : 'value7' ,
122
+ key8 : 'value8'
123
+ }
124
+ await chai . request ( app )
125
+ . put ( '/api/org/win_5' )
126
+ . set ( { ...constants . nonSecretariatUserHeaders } )
127
+ . send ( requestBody )
128
+ . then ( ( res , err ) => {
129
+ expect ( res ) . to . have . status ( 200 )
130
+ expect ( res . body . updated . last_active ) . to . not . be . null
131
+ expect ( res . body . updated . active_roles ) . to . be . undefined
132
+ expect ( res . body . updated . name ) . to . be . undefined
133
+ expect ( res . body . updated . policies ) . to . be . undefined
134
+ expect ( err ) . to . be . undefined
135
+ } )
136
+ } )
137
+ it ( 'Request body ignored in update made by secretariat to itself' , async ( ) => {
138
+ const requestBody = {
139
+ key1 : 'value1' ,
140
+ key2 : 'value2' ,
141
+ key3 : 'value3' ,
142
+ key4 : 'value4' ,
143
+ key5 : 'value5' ,
144
+ key6 : 'value6' ,
145
+ key7 : 'value7' ,
146
+ key8 : 'value8'
147
+ }
148
+ await chai . request ( app )
149
+ . put ( '/api/org/mitre' )
150
+ . set ( { ...constants . headers } )
151
+ . query ( params )
152
+ . send ( requestBody )
153
+ . then ( ( res , err ) => {
154
+ expect ( res ) . to . have . status ( 200 )
155
+ expect ( res . body . updated . last_active ) . to . not . be . null
156
+ expect ( res . body . updated . name ) . to . equal ( params . name )
157
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( params . id_quota )
158
+ expect ( err ) . to . be . undefined
159
+ } )
160
+ } )
83
161
} )
84
162
context ( 'Negative Tests' , ( ) => {
85
163
it ( 'Fails update made by a non-secretariat org to a different org' , async ( ) => {
0 commit comments