Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Middleware to Verify Scopes and reauthenticate if required #187

Merged
merged 27 commits into from
Aug 24, 2023

Conversation

usmanpakistan
Copy link
Contributor

This PR adds code to resolve issues reported in #186 #185

@Kyon147
Copy link
Owner

Kyon147 commented Jul 17, 2023

@usmanpakistan thanks for submitting the PR. It looks good but codecov is complaining because no unit tests have been set up for the new file.

Can you write a couple test for the middleware please.

@usmanpakistan
Copy link
Contributor Author

Hi @Kyon147
I did try to create a test case (not good at doing it). However, need some help. Idea is to load scopes from Shopify Config file, remove one of the scopes and then run it through the middleware. The middleware will match the installed scope with the scope in the Shopify config file. However, I cannot figure out how to emulate the Shopify API calls. Can you help me out here?

<?php

namespace Osiset\ShopifyApp\Test\Http\Middleware;

use Illuminate\Auth\AuthManager;
use Osiset\ShopifyApp\Test\TestCase;
use Osiset\ShopifyApp\Util;

class VerifyScopesTest extends TestCase{
  /**
     * @var AuthManager
     */
    protected $auth;

    public function setUp(): void
    {
        parent::setUp();

        $this->auth = $this->app->make(AuthManager::class);
    }
     public function testMissingScopes(): void
    {
        $shop = factory($this->model)->create();
        $this->auth->login($shop);
       // Get current Scopes
        $scopes = $this->app['config']->get('shopify-app.access_scopes');
        $scopes = explode(',', $scopes);
        unset($scopes[0]); 
        $newScopes = implode(',',$scopes);
        $this->app['config']->set('shopify-app.access_scopes',$newScopes);

        // Run the middleware
        $result = $this->runMiddleware(BillableMiddleware::class);
       $this->assertStatus(302);
     }
}

@Kyon147
Copy link
Owner

Kyon147 commented Jul 18, 2023

No worries @usmanpakistan if you push up the test I'll take a look and edit it 👍

@usmanpakistan
Copy link
Contributor Author

@Kyon147 Test Case added

@RishabhTayal
Copy link
Contributor

Any update on the PR?

@Kyon147
Copy link
Owner

Kyon147 commented Jul 28, 2023

Any update on the PR?

It's on my list to look at next - will see if I can squeeze this in at the weekend

@Kyon147 Kyon147 linked an issue Jul 28, 2023 that may be closed by this pull request
@Kyon147 Kyon147 merged commit 5a68ef8 into Kyon147:master Aug 24, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Scopes added to an existing app but Shopify not updating the app
3 participants