@@ -88,10 +88,13 @@ describe('RoleBindingsService', function() {
88
88
it ( 'should update the rolebinding by removing the subject from the subject list' , function ( ) {
89
89
var bindings = [ {
90
90
roleRef : { name : 'admin' } ,
91
- subjects : [ { name : 'jane' , kind : 'user' } , { name : 'jack' , kind : 'user' } ]
91
+ subjects : [
92
+ { name : 'jane' , kind : 'user' } ,
93
+ { name : 'jack' , kind : 'user' }
94
+ ]
92
95
} ] ;
93
96
RoleBindingsService
94
- . removeSubject ( 'jane' , 'admin' , bindings )
97
+ . removeSubject ( 'jane' , 'admin' , null , bindings )
95
98
. then ( function ( resp ) {
96
99
expect ( resp [ 0 ] . subjects ) . toEqual ( [ {
97
100
name : 'jack' ,
@@ -102,13 +105,61 @@ describe('RoleBindingsService', function() {
102
105
$rootScope . $digest ( ) ;
103
106
} ) ;
104
107
108
+ it ( 'should honor the namespace of a subject if provided' , function ( ) {
109
+ var bindings = [ {
110
+ roleRef : { name : 'admin' } ,
111
+ subjects : [
112
+ // multiple jim, only one should be removed in test 1
113
+ { name : 'jim' , kind : 'user' } ,
114
+ { name : 'jim' , kind : 'user' , namespace : 'yourproject' } ,
115
+ { name : 'jim' , kind : 'user' , namespace : 'myproject' } ,
116
+ { name : 'jack' , kind : 'user' }
117
+ ]
118
+ } , {
119
+ roleRef : { name : 'view' } ,
120
+ subjects : [
121
+ // multiple jane, only one should be removed in test 2
122
+ { name : 'jane' , kind : 'user' , namespace : 'myproject' } ,
123
+ { name : 'jack' , kind : 'user' , namespace : 'yourproject' } ,
124
+ { name : 'jane' , kind : 'user' , namespace : 'herproject' } ,
125
+ { name : 'jack' , kind : 'user' , namespace : 'hisproject' }
126
+ ]
127
+ } ] ;
128
+
129
+ // test 1
130
+ RoleBindingsService
131
+ . removeSubject ( 'jim' , 'admin' , 'myproject' , bindings )
132
+ . then ( function ( resp ) {
133
+ expect ( resp [ 0 ] . subjects ) . toEqual ( [
134
+ { name : 'jim' , kind : 'user' } ,
135
+ { name : 'jim' , kind : 'user' , namespace : 'yourproject' } ,
136
+ { name : 'jack' , kind : 'user' }
137
+ ] ) ;
138
+
139
+ } ) ;
140
+
141
+ // test 2
142
+ RoleBindingsService
143
+ . removeSubject ( 'jane' , 'view' , 'herproject' , bindings )
144
+ . then ( function ( resp ) {
145
+ expect ( resp [ 0 ] . subjects ) . toEqual ( [
146
+ { name : 'jane' , kind : 'user' , namespace : 'myproject' } ,
147
+ { name : 'jack' , kind : 'user' , namespace : 'yourproject' } ,
148
+ { name : 'jack' , kind : 'user' , namespace : 'hisproject' }
149
+ ] ) ;
150
+ } ) ;
151
+ // resolve $q.all() via digest loop
152
+ $rootScope . $digest ( ) ;
153
+
154
+ } ) ;
155
+
105
156
it ( 'should delete the rolebinding if the removed subject was the only subject' , function ( ) {
106
157
var bindings = [ {
107
158
roleRef : { name : 'admin' } ,
108
159
subjects : [ { name : 'jane' , kind : 'user' } ]
109
160
} ] ;
110
161
RoleBindingsService
111
- . removeSubject ( 'jane' , 'admin' , bindings )
162
+ . removeSubject ( 'jane' , 'admin' , null , bindings )
112
163
. then ( function ( resp ) {
113
164
expect ( resp [ 0 ] ) . toBe ( undefined ) ;
114
165
} ) ;
@@ -130,7 +181,7 @@ describe('RoleBindingsService', function() {
130
181
subjects : [ { name : 'jane' , kind : 'user' } , { name : 'jack' , kind : 'user' } ]
131
182
} ] ;
132
183
RoleBindingsService
133
- . removeSubject ( 'jane' , 'admin' , bindings )
184
+ . removeSubject ( 'jane' , 'admin' , null , bindings )
134
185
. then ( function ( resp ) {
135
186
_ . each ( resp , function ( roleBinding ) {
136
187
expect ( roleBinding . subjects ) . toEqual ( [ { name : 'jack' , kind : 'user' } ] ) ;
@@ -154,7 +205,7 @@ describe('RoleBindingsService', function() {
154
205
subjects : [ { name : 'jane' , kind : 'user' } ]
155
206
} ] ;
156
207
RoleBindingsService
157
- . removeSubject ( 'jane' , 'admin' , bindings )
208
+ . removeSubject ( 'jane' , 'admin' , null , bindings )
158
209
. then ( function ( resp ) {
159
210
expect ( resp [ 0 ] ) . toBe ( undefined ) ;
160
211
expect ( resp [ 1 ] . subjects ) . toEqual ( [ { name : 'jack' , kind : 'user' } ] ) ;
0 commit comments