12
12
import json
13
13
import threading
14
14
import time
15
+ import urllib
15
16
import uuid
16
17
from typing import Dict , Optional
17
18
from unittest import mock
@@ -105,6 +106,13 @@ def test_request_headers(mock_get_and_post):
105
106
headers = {
106
107
accept_encoding_header : accept_encoding_value ,
107
108
client_info_header : client_info_value ,
109
+ },
110
+ roles = {
111
+ "hive" : "ALL" ,
112
+ "system" : "analyst" ,
113
+ "catalog1" : "NONE" ,
114
+ # ensure backwards compatibility
115
+ "catalog2" : "ROLE{catalog2_role}" ,
108
116
}
109
117
),
110
118
http_scheme = "http" ,
@@ -121,7 +129,13 @@ def assert_headers(headers):
121
129
assert headers [constants .HEADER_CLIENT_CAPABILITIES ] == "PARAMETRIC_DATETIME"
122
130
assert headers [accept_encoding_header ] == accept_encoding_value
123
131
assert headers [client_info_header ] == client_info_value
124
- assert len (headers .keys ()) == 10
132
+ assert headers [constants .HEADER_ROLE ] == (
133
+ "hive=ALL,"
134
+ "system=" + urllib .parse .quote ("ROLE{analyst}" ) + ","
135
+ "catalog1=NONE,"
136
+ "catalog2=" + urllib .parse .quote ("ROLE{catalog2_role}" )
137
+ )
138
+ assert len (headers .keys ()) == 11
125
139
126
140
req .post ("URL" )
127
141
_ , post_kwargs = post .call_args
@@ -1095,14 +1109,15 @@ def test_request_headers_role_admin(mock_get_and_post):
1095
1109
roles = {"system" : "admin" }
1096
1110
),
1097
1111
)
1112
+ roles = "system=" + urllib .parse .quote ("ROLE{admin}" )
1098
1113
1099
1114
req .post ("URL" )
1100
1115
_ , post_kwargs = post .call_args
1101
- assert_headers_with_roles (post_kwargs ["headers" ], "system=admin" )
1116
+ assert_headers_with_roles (post_kwargs ["headers" ], roles )
1102
1117
1103
1118
req .get ("URL" )
1104
1119
_ , get_kwargs = get .call_args
1105
- assert_headers_with_roles (post_kwargs ["headers" ], "system=admin" )
1120
+ assert_headers_with_roles (post_kwargs ["headers" ], roles )
1106
1121
1107
1122
1108
1123
def test_request_headers_role_empty (mock_get_and_post ):
0 commit comments