@@ -37,56 +37,6 @@ func (m *mockResourcesClient) GetVersion() string {
3737
3838
3939
40- func TestVerifyApiKey (t * testing.T ) {
41- server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
42- assert .Equal (t , http .MethodPost , r .Method )
43- assert .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
44-
45- var requestBody map [string ]interface {}
46- err := json .NewDecoder (r .Body ).Decode (& requestBody )
47- assert .NoError (t , err )
48-
49- variables , ok := requestBody ["variables" ].(map [string ]interface {})
50- assert .True (t , ok )
51- assert .Equal (t , "account123" , variables ["ld_account_id" ])
52- assert .Equal (t , "project123" , variables ["ld_project_id" ])
53-
54- response := `{"data":{"ld_credential":{"project_id":"project123","api_key":"highlight-key-123"}}}`
55- w .Header ().Set ("Content-Type" , "application/json" )
56- w .WriteHeader (http .StatusOK )
57- _ , _ = w .Write ([]byte (response ))
58- }))
59- defer server .Close ()
60-
61- highlightKey , projectID , err := verifyApiKey ("account123" , "project123" , server .URL )
62- assert .NoError (t , err )
63- assert .Equal (t , "highlight-key-123" , highlightKey )
64- assert .Equal (t , "project123" , projectID )
65-
66- invalidServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
67- response := `{"data":{"ld_credential":{"project_id":"","api_key":""}}}`
68- w .Header ().Set ("Content-Type" , "application/json" )
69- w .WriteHeader (http .StatusOK )
70- _ , _ = w .Write ([]byte (response ))
71- }))
72- defer invalidServer .Close ()
73-
74- _ , _ , err = verifyApiKey ("account123" , "project123" , invalidServer .URL )
75- assert .Error (t , err )
76- assert .Contains (t , err .Error (), "invalid API key" )
77-
78- errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
79- response := `{"errors":[{"message":"Invalid credentials"}]}`
80- w .Header ().Set ("Content-Type" , "application/json" )
81- w .WriteHeader (http .StatusOK )
82- _ , _ = w .Write ([]byte (response ))
83- }))
84- defer errorServer .Close ()
85-
86- _ , _ , err = verifyApiKey ("account123" , "project123" , errorServer .URL )
87- assert .Error (t , err )
88- assert .Contains (t , err .Error (), "failed to verify API key" )
89- }
9040
9141func TestGetSourceMapUploadUrls (t * testing.T ) {
9242 server := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -102,47 +52,48 @@ func TestGetSourceMapUploadUrls(t *testing.T) {
10252 variables , ok := requestBody ["variables" ].(map [string ]interface {})
10353 assert .True (t , ok )
10454 assert .Equal (t , "test-api-key" , variables ["api_key" ])
55+ assert .Equal (t , "project123" , variables ["project_id" ])
10556 assert .NotNil (t , variables ["paths" ])
10657
107- response := `{"data":{"get_source_map_upload_urls ":["https://example.com/upload1","https://example.com/upload2"]}}`
58+ response := `{"data":{"get_source_map_upload_urls_ld ":["https://example.com/upload1","https://example.com/upload2"]}}`
10859 w .Header ().Set ("Content-Type" , "application/json" )
10960 w .WriteHeader (http .StatusOK )
11061 _ , _ = w .Write ([]byte (response ))
11162 }))
11263 defer server .Close ()
11364
11465 paths := []string {"path1" , "path2" }
115- urls , err := getSourceMapUploadUrls ("test-api-key" , paths , server .URL )
66+ urls , err := getSourceMapUploadUrls ("test-api-key" , "project123" , paths , server .URL )
11667 assert .NoError (t , err )
11768 assert .Equal (t , 2 , len (urls ))
11869 assert .Equal (t , "https://example.com/upload1" , urls [0 ])
11970 assert .Equal (t , "https://example.com/upload2" , urls [1 ])
12071
12172 errorServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
122- response := `{"data":{"get_source_map_upload_urls ":[]}}`
73+ response := `{"data":{"get_source_map_upload_urls_ld ":[]}}`
12374 w .Header ().Set ("Content-Type" , "application/json" )
12475 w .WriteHeader (http .StatusOK )
12576 _ , _ = w .Write ([]byte (response ))
12677 }))
12778 defer errorServer .Close ()
12879
129- _ , err = getSourceMapUploadUrls ("test-api-key" , paths , errorServer .URL )
80+ _ , err = getSourceMapUploadUrls ("test-api-key" , "project123" , paths , errorServer .URL )
13081 assert .Error (t , err )
13182 assert .Contains (t , err .Error (), "unable to generate source map upload urls" )
13283}
13384
13485func TestGetS3Key (t * testing.T ) {
135- key := getS3Key ("project123" , " v1.0" , "base/path" , "file.js.map" )
136- assert .Equal (t , "project123/ v1.0/base/path/file.js.map" , key )
86+ key := getS3Key ("v1.0" , "base/path" , "file.js.map" )
87+ assert .Equal (t , "v1.0/base/path/file.js.map" , key )
13788
138- key = getS3Key ("project123" , " " , "base/path" , "file.js.map" )
139- assert .Equal (t , "project123/ unversioned/base/path/file.js.map" , key )
89+ key = getS3Key ("" , "base/path" , "file.js.map" )
90+ assert .Equal (t , "unversioned/base/path/file.js.map" , key )
14091
141- key = getS3Key ("project123" , " v1.0" , "" , "file.js.map" )
142- assert .Equal (t , "project123/ v1.0/file.js.map" , key )
92+ key = getS3Key ("v1.0" , "" , "file.js.map" )
93+ assert .Equal (t , "v1.0/file.js.map" , key )
14394
144- key = getS3Key ("project123" , " v1.0" , "base/path" , "file.js.map" )
145- assert .Equal (t , "project123/ v1.0/base/path/file.js.map" , key )
95+ key = getS3Key ("v1.0" , "base/path" , "file.js.map" )
96+ assert .Equal (t , "v1.0/base/path/file.js.map" , key )
14697}
14798
14899func TestUploadFile (t * testing.T ) {
@@ -249,29 +200,12 @@ func TestGetAllSourceMapFiles(t *testing.T) {
249200 assert .Contains (t , err .Error (), "no .js.map files found" )
250201}
251202
252- func TestVerifyApiKeyErrors (t * testing.T ) {
253- _ , _ , err := verifyApiKey ("account123" , "project123" , "://invalid-url" )
254- assert .Error (t , err )
255-
256- _ , _ , err = verifyApiKey ("account123" , "project123" , "http://non-existent-host.invalid" )
257- assert .Error (t , err )
258-
259- invalidJSONServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
260- w .Header ().Set ("Content-Type" , "application/json" )
261- w .WriteHeader (http .StatusOK )
262- _ , _ = w .Write ([]byte (`{"data":invalid-json` ))
263- }))
264- defer invalidJSONServer .Close ()
265-
266- _ , _ , err = verifyApiKey ("account123" , "project123" , invalidJSONServer .URL )
267- assert .Error (t , err )
268- }
269203
270204func TestGetSourceMapUploadUrlsErrors (t * testing.T ) {
271- _ , err := getSourceMapUploadUrls ("test-key" , []string {"path" }, "://invalid-url" )
205+ _ , err := getSourceMapUploadUrls ("test-key" , "project123" , []string {"path" }, "://invalid-url" )
272206 assert .Error (t , err )
273207
274- _ , err = getSourceMapUploadUrls ("test-key" , []string {"path" }, "http://non-existent-host.invalid" )
208+ _ , err = getSourceMapUploadUrls ("test-key" , "project123" , []string {"path" }, "http://non-existent-host.invalid" )
275209 assert .Error (t , err )
276210
277211 invalidJSONServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
@@ -281,16 +215,15 @@ func TestGetSourceMapUploadUrlsErrors(t *testing.T) {
281215 }))
282216 defer invalidJSONServer .Close ()
283217
284- _ , err = getSourceMapUploadUrls ("test-key" , []string {"path" }, invalidJSONServer .URL )
218+ _ , err = getSourceMapUploadUrls ("test-key" , "project123" , []string {"path" }, invalidJSONServer .URL )
285219 assert .Error (t , err )
286220}
287221
288222func TestRunE (t * testing.T ) {
289223 // Create a mock client that returns predefined responses
290224 mockClient := & mockResourcesClient {
291225 responses : map [string ][]byte {
292- "/api/v2/caller-identity" : []byte (`{"AccountID":"account123"}` ),
293- "/api/v2/projects/test-project" : []byte (`{"Items":[{"_id":"project123"}]}` ),
226+ "/api/v2/projects/test-project" : []byte (`{"_id":"project123"}` ),
294227 },
295228 }
296229
@@ -305,16 +238,8 @@ func TestRunE(t *testing.T) {
305238 err = os .WriteFile (testMapFile , []byte ("{}" ), 0644 )
306239 assert .NoError (t , err )
307240
308- verifyServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
309- response := `{"data":{"ld_credential":{"project_id":"project123","api_key":"highlight-key-123"}}}`
310- w .Header ().Set ("Content-Type" , "application/json" )
311- w .WriteHeader (http .StatusOK )
312- _ , _ = w .Write ([]byte (response ))
313- }))
314- defer verifyServer .Close ()
315-
316241 urlsServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
317- response := `{"data":{"get_source_map_upload_urls ":["https://example.com/upload"]}}`
242+ response := `{"data":{"get_source_map_upload_urls_ld ":["https://example.com/upload"]}}`
318243 w .Header ().Set ("Content-Type" , "application/json" )
319244 w .WriteHeader (http .StatusOK )
320245 _ , _ = w .Write ([]byte (response ))
@@ -334,7 +259,7 @@ func TestRunE(t *testing.T) {
334259 assert .NoError (t , err )
335260 err = cmd .Flags ().Set (pathFlag , testMapFile )
336261 assert .NoError (t , err )
337- err = cmd .Flags ().Set (backendUrlFlag , verifyServer .URL )
262+ err = cmd .Flags ().Set (backendUrlFlag , urlsServer .URL )
338263 assert .NoError (t , err )
339264
340265 err = runFunc (cmd , args )
0 commit comments