|
| 1 | +@RHIdentity |
| 2 | +Feature: Authorized endpoint API tests for the rh-identity authentication module |
| 3 | + |
| 4 | + Background: |
| 5 | + Given The service is started locally |
| 6 | + And REST API service prefix is /v1 |
| 7 | + |
| 8 | + Scenario: Request fails when x-rh-identity header is missing |
| 9 | + Given The system is in default state |
| 10 | + When I access endpoint "authorized" using HTTP POST method |
| 11 | + """ |
| 12 | + {"placeholder":"abc"} |
| 13 | + """ |
| 14 | + Then The status code of the response is 401 |
| 15 | + And The body of the response is the following |
| 16 | + """ |
| 17 | + {"detail": "Missing x-rh-identity header"} |
| 18 | + """ |
| 19 | + |
| 20 | + Scenario: Request fails when x-rh-identity header has invalid base64 |
| 21 | + Given The system is in default state |
| 22 | + And I set the x-rh-identity header to raw value "not-valid-base64!!!" |
| 23 | + When I access endpoint "authorized" using HTTP POST method |
| 24 | + """ |
| 25 | + {"placeholder":"abc"} |
| 26 | + """ |
| 27 | + Then The status code of the response is 400 |
| 28 | + And The body of the response contains "Invalid base64 encoding" |
| 29 | + |
| 30 | + Scenario: Request fails when x-rh-identity header has invalid JSON |
| 31 | + Given The system is in default state |
| 32 | + And I set the x-rh-identity header with base64 encoded value "{not valid json" |
| 33 | + When I access endpoint "authorized" using HTTP POST method |
| 34 | + """ |
| 35 | + {"placeholder":"abc"} |
| 36 | + """ |
| 37 | + Then The status code of the response is 400 |
| 38 | + And The body of the response contains "Invalid JSON" |
| 39 | + |
| 40 | + Scenario: Request fails when identity field is missing |
| 41 | + Given The system is in default state |
| 42 | + And I set the x-rh-identity header with JSON |
| 43 | + """ |
| 44 | + {"entitlements": {"rhel": {"is_entitled": true}}} |
| 45 | + """ |
| 46 | + When I access endpoint "authorized" using HTTP POST method |
| 47 | + """ |
| 48 | + {"placeholder":"abc"} |
| 49 | + """ |
| 50 | + Then The status code of the response is 400 |
| 51 | + And The body of the response contains "Missing 'identity' field" |
| 52 | + |
| 53 | + Scenario: Request fails when identity field is null |
| 54 | + Given The system is in default state |
| 55 | + And I set the x-rh-identity header with JSON |
| 56 | + """ |
| 57 | + {"identity": null, "entitlements": {"rhel": {"is_entitled": true}}} |
| 58 | + """ |
| 59 | + When I access endpoint "authorized" using HTTP POST method |
| 60 | + """ |
| 61 | + {"placeholder":"abc"} |
| 62 | + """ |
| 63 | + Then The status code of the response is 400 |
| 64 | + And The body of the response contains "Missing 'identity' field" |
| 65 | + |
| 66 | + Scenario: Request fails when identity type field is missing |
| 67 | + Given The system is in default state |
| 68 | + And I set the x-rh-identity header with JSON |
| 69 | + """ |
| 70 | + {"identity": {"org_id": "321"}, "entitlements": {"rhel": {"is_entitled": true}}} |
| 71 | + """ |
| 72 | + When I access endpoint "authorized" using HTTP POST method |
| 73 | + """ |
| 74 | + {"placeholder":"abc"} |
| 75 | + """ |
| 76 | + Then The status code of the response is 400 |
| 77 | + And The body of the response contains "Missing identity 'type' field" |
| 78 | + |
| 79 | + Scenario: Request fails with unsupported identity type |
| 80 | + Given The system is in default state |
| 81 | + And I set the x-rh-identity header with JSON |
| 82 | + """ |
| 83 | + {"identity": {"type": "Unknown", "org_id": "123"}} |
| 84 | + """ |
| 85 | + When I access endpoint "authorized" using HTTP POST method |
| 86 | + """ |
| 87 | + {"placeholder":"abc"} |
| 88 | + """ |
| 89 | + Then The status code of the response is 400 |
| 90 | + And The body of the response contains "Unsupported identity type" |
| 91 | + |
| 92 | + Scenario: Request succeeds with valid User identity and required entitlements |
| 93 | + Given The system is in default state |
| 94 | + And I set the x-rh-identity header with valid User identity |
| 95 | + | field | value | |
| 96 | + | user_id | test-user-123 | |
| 97 | + | username | testuser@redhat.com | |
| 98 | + | org_id | 321 | |
| 99 | + | entitlements | rhel | |
| 100 | + When I access endpoint "authorized" using HTTP POST method |
| 101 | + """ |
| 102 | + {"placeholder":"abc"} |
| 103 | + """ |
| 104 | + Then The status code of the response is 200 |
| 105 | + |
| 106 | + Scenario: Request succeeds with valid System identity and required entitlements |
| 107 | + Given The system is in default state |
| 108 | + And I set the x-rh-identity header with valid System identity |
| 109 | + | field | value | |
| 110 | + | cn | c87dcb4c-8af1-40dd-878e-60c744edddd0 | |
| 111 | + | account_number | 456 | |
| 112 | + | org_id | 654 | |
| 113 | + | entitlements | rhel | |
| 114 | + When I access endpoint "authorized" using HTTP POST method |
| 115 | + """ |
| 116 | + {"placeholder":"abc"} |
| 117 | + """ |
| 118 | + Then The status code of the response is 200 |
| 119 | + |
| 120 | + Scenario: Request fails when required entitlement is missing |
| 121 | + Given The system is in default state |
| 122 | + And I set the x-rh-identity header with valid User identity |
| 123 | + | field | value | |
| 124 | + | user_id | test-user-123 | |
| 125 | + | username | testuser@redhat.com | |
| 126 | + | org_id | 321 | |
| 127 | + | entitlements | ansible | |
| 128 | + When I access endpoint "authorized" using HTTP POST method |
| 129 | + """ |
| 130 | + {"placeholder":"abc"} |
| 131 | + """ |
| 132 | + Then The status code of the response is 403 |
| 133 | + And The body of the response contains "Missing required entitlement" |
| 134 | + |
| 135 | + Scenario: Request fails when user has no entitlements |
| 136 | + Given The system is in default state |
| 137 | + And I set the x-rh-identity header with JSON |
| 138 | + """ |
| 139 | + { |
| 140 | + "identity": { |
| 141 | + "type": "User", |
| 142 | + "org_id": "321", |
| 143 | + "user": {"user_id": "test-user-123", "username": "testuser@redhat.com"} |
| 144 | + }, |
| 145 | + "entitlements": {} |
| 146 | + } |
| 147 | + """ |
| 148 | + When I access endpoint "authorized" using HTTP POST method |
| 149 | + """ |
| 150 | + {"placeholder":"abc"} |
| 151 | + """ |
| 152 | + Then The status code of the response is 403 |
| 153 | + And The body of the response contains "Missing required entitlement" |
| 154 | + |
| 155 | + Scenario: Request fails when entitlement exists but is_entitled is false |
| 156 | + Given The system is in default state |
| 157 | + And I set the x-rh-identity header with JSON |
| 158 | + """ |
| 159 | + { |
| 160 | + "identity": { |
| 161 | + "type": "User", |
| 162 | + "org_id": "321", |
| 163 | + "user": {"user_id": "test-user-123", "username": "testuser@redhat.com"} |
| 164 | + }, |
| 165 | + "entitlements": {"rhel": {"is_entitled": false, "is_trial": true}} |
| 166 | + } |
| 167 | + """ |
| 168 | + When I access endpoint "authorized" using HTTP POST method |
| 169 | + """ |
| 170 | + {"placeholder":"abc"} |
| 171 | + """ |
| 172 | + Then The status code of the response is 403 |
| 173 | + And The body of the response contains "Missing required entitlement" |
| 174 | + |
| 175 | + Scenario: Request fails when User identity is missing user field |
| 176 | + Given The system is in default state |
| 177 | + And I set the x-rh-identity header with JSON |
| 178 | + """ |
| 179 | + { |
| 180 | + "identity": { |
| 181 | + "type": "User", |
| 182 | + "org_id": "321" |
| 183 | + }, |
| 184 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 185 | + } |
| 186 | + """ |
| 187 | + When I access endpoint "authorized" using HTTP POST method |
| 188 | + """ |
| 189 | + {"placeholder":"abc"} |
| 190 | + """ |
| 191 | + Then The status code of the response is 400 |
| 192 | + And The body of the response contains "Missing 'user' field for User type" |
| 193 | + |
| 194 | + Scenario: Request fails when User identity is missing user_id |
| 195 | + Given The system is in default state |
| 196 | + And I set the x-rh-identity header with JSON |
| 197 | + """ |
| 198 | + { |
| 199 | + "identity": { |
| 200 | + "type": "User", |
| 201 | + "org_id": "321", |
| 202 | + "user": {"username": "testuser@redhat.com"} |
| 203 | + }, |
| 204 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 205 | + } |
| 206 | + """ |
| 207 | + When I access endpoint "authorized" using HTTP POST method |
| 208 | + """ |
| 209 | + {"placeholder":"abc"} |
| 210 | + """ |
| 211 | + Then The status code of the response is 400 |
| 212 | + And The body of the response contains "Missing 'user_id' in user data" |
| 213 | + |
| 214 | + Scenario: Request fails when User identity is missing username |
| 215 | + Given The system is in default state |
| 216 | + And I set the x-rh-identity header with JSON |
| 217 | + """ |
| 218 | + { |
| 219 | + "identity": { |
| 220 | + "type": "User", |
| 221 | + "org_id": "321", |
| 222 | + "user": {"user_id": "test-user-123"} |
| 223 | + }, |
| 224 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 225 | + } |
| 226 | + """ |
| 227 | + When I access endpoint "authorized" using HTTP POST method |
| 228 | + """ |
| 229 | + {"placeholder":"abc"} |
| 230 | + """ |
| 231 | + Then The status code of the response is 400 |
| 232 | + And The body of the response contains "Missing 'username' in user data" |
| 233 | + |
| 234 | + Scenario: Request fails when System identity is missing system field |
| 235 | + Given The system is in default state |
| 236 | + And I set the x-rh-identity header with JSON |
| 237 | + """ |
| 238 | + { |
| 239 | + "identity": { |
| 240 | + "type": "System", |
| 241 | + "account_number": "456", |
| 242 | + "org_id": "654" |
| 243 | + }, |
| 244 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 245 | + } |
| 246 | + """ |
| 247 | + When I access endpoint "authorized" using HTTP POST method |
| 248 | + """ |
| 249 | + {"placeholder":"abc"} |
| 250 | + """ |
| 251 | + Then The status code of the response is 400 |
| 252 | + And The body of the response contains "Missing 'system' field for System type" |
| 253 | + |
| 254 | + Scenario: Request fails when System identity is missing cn |
| 255 | + Given The system is in default state |
| 256 | + And I set the x-rh-identity header with JSON |
| 257 | + """ |
| 258 | + { |
| 259 | + "identity": { |
| 260 | + "type": "System", |
| 261 | + "account_number": "456", |
| 262 | + "org_id": "654", |
| 263 | + "system": {} |
| 264 | + }, |
| 265 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 266 | + } |
| 267 | + """ |
| 268 | + When I access endpoint "authorized" using HTTP POST method |
| 269 | + """ |
| 270 | + {"placeholder":"abc"} |
| 271 | + """ |
| 272 | + Then The status code of the response is 400 |
| 273 | + And The body of the response contains "Missing 'cn' in system data" |
| 274 | + |
| 275 | + Scenario: Request fails when System identity is missing account_number |
| 276 | + Given The system is in default state |
| 277 | + And I set the x-rh-identity header with JSON |
| 278 | + """ |
| 279 | + { |
| 280 | + "identity": { |
| 281 | + "type": "System", |
| 282 | + "org_id": "654", |
| 283 | + "system": {"cn": "c87dcb4c-8af1-40dd-878e-60c744edddd0"} |
| 284 | + }, |
| 285 | + "entitlements": {"rhel": {"is_entitled": true}} |
| 286 | + } |
| 287 | + """ |
| 288 | + When I access endpoint "authorized" using HTTP POST method |
| 289 | + """ |
| 290 | + {"placeholder":"abc"} |
| 291 | + """ |
| 292 | + Then The status code of the response is 400 |
| 293 | + And The body of the response contains "Missing 'account_number' for System type" |
0 commit comments