@@ -259,31 +259,58 @@ func TestCardGetEmbedHTMLWithOptionalParams(t *testing.T) {
259259 }
260260}
261261
262- func TestCardGetEmbedURLWithOptionalParams (t * testing.T ) {
263- baseURL := "http://localhost:4010"
264- if envURL , ok := os .LookupEnv ("TEST_API_BASE_URL" ); ok {
265- baseURL = envURL
266- }
267- if ! testutil .CheckTestServer (t , baseURL ) {
268- return
269- }
262+ func TestCardGetEmbedURL_URLConstruction (t * testing.T ) {
263+ // Use fixed inputs to verify URL construction and signature
270264 client := lithic .NewClient (
271- option .WithBaseURL (baseURL ),
272- option .WithAPIKey ("My Lithic API Key " ),
265+ option .WithBaseURL ("https://sandbox.lithic.com" ),
266+ option .WithAPIKey ("test-api-key-12345 " ),
273267 )
274- _ , err := client .Cards .GetEmbedURL (context .TODO (), lithic.CardGetEmbedURLParams {
275- Token : lithic .F ("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e" ),
276- Css : lithic .F ("string" ),
277- Expiration : lithic .F (time .Now ()),
278- TargetOrigin : lithic .F ("string" ),
268+
269+ expiration , err := time .Parse (time .RFC3339 , "2025-01-01T00:00:00Z" )
270+ if err != nil {
271+ t .Fatalf ("failed to parse expiration: %s" , err .Error ())
272+ }
273+
274+ url , err := client .Cards .GetEmbedURL (context .TODO (), lithic.CardGetEmbedURLParams {
275+ Token : lithic .F ("test-card-token-abc123" ),
276+ Css : lithic .F ("https://example.com/style.css" ),
277+ Expiration : lithic .F (expiration ),
278+ TargetOrigin : lithic .F ("https://example.com" ),
279279 })
280280 if err != nil {
281- var apierr * lithic.Error
282- if errors .As (err , & apierr ) {
283- t .Log (string (apierr .DumpRequest (true )))
284- }
285281 t .Fatalf ("err should be nil: %s" , err .Error ())
286282 }
283+
284+ // Verify URL structure
285+ if url .Scheme != "https" {
286+ t .Errorf ("expected scheme 'https', got '%s'" , url .Scheme )
287+ }
288+ if url .Host != "sandbox.lithic.com" {
289+ t .Errorf ("expected host 'sandbox.lithic.com', got '%s'" , url .Host )
290+ }
291+ if url .Path != "/v1/embed/card" {
292+ t .Errorf ("expected path '/v1/embed/card', got '%s'" , url .Path )
293+ }
294+
295+ // Verify query params exist
296+ query := url .Query ()
297+ if query .Get ("embed_request" ) == "" {
298+ t .Error ("expected 'embed_request' query param to be present" )
299+ }
300+ if query .Get ("hmac" ) == "" {
301+ t .Error ("expected 'hmac' query param to be present" )
302+ }
303+
304+ // Verify exact values to prevent signature regressions
305+ expectedEmbedRequest := "eyJjc3MiOiJodHRwczovL2V4YW1wbGUuY29tL3N0eWxlLmNzcyIsImV4cGlyYXRpb24iOiIyMDI1LTAxLTAxVDAwOjAwOjAwWiIsInRhcmdldF9vcmlnaW4iOiJodHRwczovL2V4YW1wbGUuY29tIiwidG9rZW4iOiJ0ZXN0LWNhcmQtdG9rZW4tYWJjMTIzIn0="
306+ expectedHmac := "tHf1AsLDIO7gHDA+N/3d5RT446tSmorVbjELGXF/UKQ="
307+
308+ if query .Get ("embed_request" ) != expectedEmbedRequest {
309+ t .Errorf ("embed_request mismatch:\n got: %s\n want: %s" , query .Get ("embed_request" ), expectedEmbedRequest )
310+ }
311+ if query .Get ("hmac" ) != expectedHmac {
312+ t .Errorf ("hmac mismatch:\n got: %s\n want: %s" , query .Get ("hmac" ), expectedHmac )
313+ }
287314}
288315
289316func TestCardProvisionWithOptionalParams (t * testing.T ) {
0 commit comments