@@ -65,6 +65,75 @@ public function testDebugEnabled()
6565 $ this ->assertStringContainsString ('ck-debug.INFO: Finish request successfully ' , $ this ->getLogFileContents ());
6666 }
6767
68+ /**
69+ * Test that debug logging works when enabled, a custom debug log file and path is specified
70+ * and an API call is made.
71+ *
72+ * @since 1.3.0
73+ *
74+ * @return void
75+ */
76+ public function testDebugEnabledWithCustomLogFile ()
77+ {
78+ // Define custom log file location.
79+ $ this ->logFile = dirname (dirname (__FILE__ )) . '/src/logs/debug-custom.log ' ;
80+
81+ // Setup API with debugging enabled.
82+ $ api = new \ConvertKit_API \ConvertKit_API (
83+ $ _ENV ['CONVERTKIT_API_KEY ' ],
84+ $ _ENV ['CONVERTKIT_API_SECRET ' ],
85+ true ,
86+ $ this ->logFile
87+ );
88+ $ result = $ api ->get_account ();
89+
90+ // Confirm log file exists.
91+ $ this ->assertFileExists ($ this ->logFile );
92+
93+ // Confirm that the log includes expected data.
94+ $ this ->assertStringContainsString ('ck-debug.INFO: GET account ' , $ this ->getLogFileContents ());
95+ $ this ->assertStringContainsString ('ck-debug.INFO: Finish request successfully ' , $ this ->getLogFileContents ());
96+ }
97+
98+ /**
99+ * Test that debug logging works when enabled and an API call is made, with the API Key and Secret
100+ * masked in the log file.
101+ *
102+ * @since 1.3.0
103+ *
104+ * @return void
105+ */
106+ public function testDebugAPIKeyAndSecretAreMasked ()
107+ {
108+ // Setup API with debugging enabled.
109+ $ api = new \ConvertKit_API \ConvertKit_API ($ _ENV ['CONVERTKIT_API_KEY ' ], $ _ENV ['CONVERTKIT_API_SECRET ' ], true );
110+
111+ // Make requests that utilizes both the API Key and Secret.
112+ $ api ->get_forms (); // API Key.
113+ $ api ->get_account (); // API Secret.
114+
115+ // Define masked versions of API Key and Secret that we expect to see in the log file.
116+ $ maskedAPIKey = str_replace (
117+ $ _ENV ['CONVERTKIT_API_KEY ' ],
118+ str_repeat ('* ' , strlen ($ _ENV ['CONVERTKIT_API_KEY ' ]) - 4 ) . substr ($ _ENV ['CONVERTKIT_API_KEY ' ], - 4 ),
119+ $ _ENV ['CONVERTKIT_API_KEY ' ]
120+ );
121+ $ maskedAPISecret = str_replace (
122+ $ _ENV ['CONVERTKIT_API_SECRET ' ],
123+ str_repeat ('* ' , strlen ($ _ENV ['CONVERTKIT_API_SECRET ' ]) - 4 ) . substr ($ _ENV ['CONVERTKIT_API_SECRET ' ], - 4 ),
124+ $ _ENV ['CONVERTKIT_API_SECRET ' ]
125+ );
126+
127+
128+ // Confirm that the log includes the masked API Key and Secret.
129+ $ this ->assertStringContainsString ($ maskedAPIKey , $ this ->getLogFileContents ());
130+ $ this ->assertStringContainsString ($ maskedAPISecret , $ this ->getLogFileContents ());
131+
132+ // Confirm that the log does not include the unmasked API Key and Secret.
133+ $ this ->assertStringNotContainsString ($ _ENV ['CONVERTKIT_API_KEY ' ], $ this ->getLogFileContents ());
134+ $ this ->assertStringNotContainsString ($ _ENV ['CONVERTKIT_API_SECRET ' ], $ this ->getLogFileContents ());
135+ }
136+
68137 /**
69138 * Test that debug logging is not performed when disabled and an API call is made.
70139 *
0 commit comments