@@ -107,6 +107,75 @@ public function testDebugEnabled()
107
107
$ this ->assertStringContainsString ('ck-debug.INFO: Finish request successfully ' , $ this ->getLogFileContents ());
108
108
}
109
109
110
+ /**
111
+ * Test that debug logging works when enabled, a custom debug log file and path is specified
112
+ * and an API call is made.
113
+ *
114
+ * @since 1.3.0
115
+ *
116
+ * @return void
117
+ */
118
+ public function testDebugEnabledWithCustomLogFile ()
119
+ {
120
+ // Define custom log file location.
121
+ $ this ->logFile = dirname (dirname (__FILE__ )) . '/src/logs/debug-custom.log ' ;
122
+
123
+ // Setup API with debugging enabled.
124
+ $ api = new \ConvertKit_API \ConvertKit_API (
125
+ $ _ENV ['CONVERTKIT_API_KEY ' ],
126
+ $ _ENV ['CONVERTKIT_API_SECRET ' ],
127
+ true ,
128
+ $ this ->logFile
129
+ );
130
+ $ result = $ api ->get_account ();
131
+
132
+ // Confirm log file exists.
133
+ $ this ->assertFileExists ($ this ->logFile );
134
+
135
+ // Confirm that the log includes expected data.
136
+ $ this ->assertStringContainsString ('ck-debug.INFO: GET account ' , $ this ->getLogFileContents ());
137
+ $ this ->assertStringContainsString ('ck-debug.INFO: Finish request successfully ' , $ this ->getLogFileContents ());
138
+ }
139
+
140
+ /**
141
+ * Test that debug logging works when enabled and an API call is made, with the API Key and Secret
142
+ * masked in the log file.
143
+ *
144
+ * @since 1.3.0
145
+ *
146
+ * @return void
147
+ */
148
+ public function testDebugAPIKeyAndSecretAreMasked ()
149
+ {
150
+ // Setup API with debugging enabled.
151
+ $ api = new \ConvertKit_API \ConvertKit_API ($ _ENV ['CONVERTKIT_API_KEY ' ], $ _ENV ['CONVERTKIT_API_SECRET ' ], true );
152
+
153
+ // Make requests that utilizes both the API Key and Secret.
154
+ $ api ->get_forms (); // API Key.
155
+ $ api ->get_account (); // API Secret.
156
+
157
+ // Define masked versions of API Key and Secret that we expect to see in the log file.
158
+ $ maskedAPIKey = str_replace (
159
+ $ _ENV ['CONVERTKIT_API_KEY ' ],
160
+ str_repeat ('* ' , strlen ($ _ENV ['CONVERTKIT_API_KEY ' ]) - 4 ) . substr ($ _ENV ['CONVERTKIT_API_KEY ' ], - 4 ),
161
+ $ _ENV ['CONVERTKIT_API_KEY ' ]
162
+ );
163
+ $ maskedAPISecret = str_replace (
164
+ $ _ENV ['CONVERTKIT_API_SECRET ' ],
165
+ str_repeat ('* ' , strlen ($ _ENV ['CONVERTKIT_API_SECRET ' ]) - 4 ) . substr ($ _ENV ['CONVERTKIT_API_SECRET ' ], - 4 ),
166
+ $ _ENV ['CONVERTKIT_API_SECRET ' ]
167
+ );
168
+
169
+
170
+ // Confirm that the log includes the masked API Key and Secret.
171
+ $ this ->assertStringContainsString ($ maskedAPIKey , $ this ->getLogFileContents ());
172
+ $ this ->assertStringContainsString ($ maskedAPISecret , $ this ->getLogFileContents ());
173
+
174
+ // Confirm that the log does not include the unmasked API Key and Secret.
175
+ $ this ->assertStringNotContainsString ($ _ENV ['CONVERTKIT_API_KEY ' ], $ this ->getLogFileContents ());
176
+ $ this ->assertStringNotContainsString ($ _ENV ['CONVERTKIT_API_SECRET ' ], $ this ->getLogFileContents ());
177
+ }
178
+
110
179
/**
111
180
* Test that debug logging is not performed when disabled and an API call is made.
112
181
*
0 commit comments