Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
n7studios committed Jun 26, 2024
1 parent cf2d23b commit 56c7547
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/class-convertkit-api-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private function delete_code_verifier() {
* @param string $str String to encode.
* @return Encoded string.
*/
private function base64_urlencode( $str ) {
public function base64_urlencode( $str ) {

// Encode to Base64 string.
$str = base64_encode( $str ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
Expand All @@ -339,10 +339,10 @@ private function base64_urlencode( $str ) {
*
* @since 2.0.0
*
* @param string $state State.
* @return string OAuth URL
* @param string $return_url Return URL.
* @return string OAuth URL
*/
public function get_oauth_url( $state = false ) {
public function get_oauth_url( $return_url = false ) {

// Generate and store code verifier and challenge.
$code_verifier = $this->generate_and_store_code_verifier();
Expand All @@ -357,11 +357,11 @@ public function get_oauth_url( $state = false ) {
'code_challenge_method' => 'S256',
);

if ( $state ) {
if ( $return_url ) {
$args['state'] = $this->base64_urlencode(
wp_json_encode(
array(
'return_to' => $state,
'return_to' => $return_url,
'client_id' => $this->client_id,
)
)
Expand Down
11 changes: 9 additions & 2 deletions tests/wpunit/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,22 @@ public function testGetOAuthURLWithState()
{
// Confirm the OAuth URL returned is correct.
$this->assertEquals(
$this->api->get_oauth_url( 'an-example-state' ),
$this->api->get_oauth_url( 'https://example.com' ),
'https://app.convertkit.com/oauth/authorize?' . http_build_query(
[
'client_id' => $_ENV['CONVERTKIT_OAUTH_CLIENT_ID'],
'response_type' => 'code',
'redirect_uri' => $_ENV['CONVERTKIT_OAUTH_REDIRECT_URI'],
'code_challenge' => $this->api->generate_code_challenge( $this->api->get_code_verifier() ),
'code_challenge_method' => 'S256',
'state' => 'an-example-state',
'state' => $this->api->base64_urlencode(
wp_json_encode(
array(
'return_to' => 'https://example.com',
'client_id' => $_ENV['CONVERTKIT_OAUTH_CLIENT_ID'],
)
)
),
]
)
);
Expand Down

0 comments on commit 56c7547

Please sign in to comment.