From 2bef46073d6ae514d4991f5c2c6f50ab8b3bfbfd Mon Sep 17 00:00:00 2001 From: Martin Gingras Date: Mon, 23 Mar 2020 16:32:47 -0400 Subject: [PATCH 1/3] Fix reload command for fish shell users --- shopify.fish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shopify.fish b/shopify.fish index eba6e743af..fdef6afe82 100755 --- a/shopify.fish +++ b/shopify.fish @@ -72,8 +72,8 @@ function __shopify__ case setenv:\* set -l assignment (echo "$fin" | sed 's/^setenv://' | tr = \\n) set -x "$assignment[1]" "$assignment[2]" - case reload_shopify_from:\* - set -l root (echo "$fin" | sed 's/^reload_shopify_from://') + case reload_shopify_cli_from:\* + set -l root (echo "$fin" | sed 's/^reload_shopify_cli_from://') source "$root/shopify.fish" end end < "$finalizers" From 2d2ea748dfa1bc01485f2763c86cdab23e405dd2 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Mon, 23 Mar 2020 16:35:06 -0400 Subject: [PATCH 2/3] Little change to Oauth request parsing --- lib/shopify-cli/oauth.rb | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib/shopify-cli/oauth.rb b/lib/shopify-cli/oauth.rb index db49bb5a87..3ced99b386 100644 --- a/lib/shopify-cli/oauth.rb +++ b/lib/shopify-cli/oauth.rb @@ -14,6 +14,7 @@ class OAuth include Helpers::OS class Error < StandardError; end + LocalRequest = Struct.new(:method, :path, :query, :protocol) DEFAULT_PORT = 3456 REDIRECT_HOST = "http://app-cli-loopback.shopifyapps.com:#{DEFAULT_PORT}" @@ -90,16 +91,16 @@ def listen_local Thread.current.abort_on_exception = true begin socket = server.accept - query = Hash[URI.decode_www_form(socket.gets.split[1][2..-1])] - if !query['error'].nil? - respond_with(socket, 400, "Invalid Request: #{query['error_description']}") - elsif query['state'] != state_token - query.merge!('error' => 'invalid_state', 'error_description' => INVALID_STATE_RESP) + req = decode_request(socket.gets) + if !req.query['error'].nil? + respond_with(socket, 400, "Invalid Request: #{req.query['error_description']}") + elsif req.query['state'] != state_token + req.query.merge!('error' => 'invalid_state', 'error_description' => INVALID_STATE_RESP) respond_with(socket, 403, INVALID_STATE_RESP) else respond_with(socket, 200, SUCCESS_RESP) end - query + req.query ensure socket.close_write server.close @@ -107,6 +108,24 @@ def listen_local end end + def decode_request(req) + data = LocalRequest.new + data.method, path, data.protocol = req.split(' ') + data.path, _sep, query = path.partition("?") + data.query = decode_request_params(query) + data + end + + def decode_request_params(str) + str.b.split('&').each_with_object({}) do |string, params| + key, _sep, val = string.partition('=') + key = URI.decode_www_form_component(key) + val = URI.decode_www_form_component(val) + params[key] = val + params + end + end + def receive_access_code @access_code ||= begin server = @server_thread.join(60) From fa7bc28007b6eeda1ae4e8c06ca19d0fec62378d Mon Sep 17 00:00:00 2001 From: Jacob Steves Date: Mon, 30 Mar 2020 13:54:38 -0400 Subject: [PATCH 3/3] abort when rescuing 404 from parters in authenticated_req --- lib/shopify-cli/helpers/partners_api.rb | 2 +- test/shopify-cli/helpers/partners_api_test.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/shopify-cli/helpers/partners_api.rb b/lib/shopify-cli/helpers/partners_api.rb index 50a53dbb1b..8f13c52db6 100644 --- a/lib/shopify-cli/helpers/partners_api.rb +++ b/lib/shopify-cli/helpers/partners_api.rb @@ -44,7 +44,7 @@ def authenticated_req(ctx) Tasks::AuthenticateIdentity.call(ctx) retry rescue API::APIRequestNotFoundError - ctx.puts("{{x}} error: Your account was not found. Please sign up at https://partners.shopify.com/signup") + ctx.error("error: Your account was not found. Please sign up at https://partners.shopify.com/signup") end def api_client(ctx) diff --git a/test/shopify-cli/helpers/partners_api_test.rb b/test/shopify-cli/helpers/partners_api_test.rb index 6498b46b09..e85defaaaa 100644 --- a/test/shopify-cli/helpers/partners_api_test.rb +++ b/test/shopify-cli/helpers/partners_api_test.rb @@ -62,7 +62,7 @@ def test_query_can_reauth PartnersAPI.query(@context, 'query') end - def test_query_fails_gracefully_without_partners_account + def test_query_aborts_without_partners_account api_stub = Object.new PartnersAPI.expects(:new).with( ctx: @context, @@ -70,10 +70,13 @@ def test_query_fails_gracefully_without_partners_account url: "#{PartnersAPI.endpoint}/api/cli/graphql", ).returns(api_stub) api_stub.expects(:query).raises(API::APIRequestNotFoundError) - @context.expects(:puts).with( - "{{x}} error: Your account was not found. Please sign up at https://partners.shopify.com/signup", + e = assert_raises ShopifyCli::Abort do + PartnersAPI.query(@context, 'query') + end + assert_match( + 'error: Your account was not found. Please sign up at https://partners.shopify.com/signup', + e.message ) - PartnersAPI.query(@context, 'query') end def test_query