From e546e468c24d4ef654aeac1cdf064bdd930d00f4 Mon Sep 17 00:00:00 2001 From: Rimian Perkins Date: Fri, 9 Sep 2022 14:37:08 +1000 Subject: [PATCH] add a validation helper for client_id --- lib/xero-ruby/api_client.rb | 4 ++++ spec/api_client_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/xero-ruby/api_client.rb b/lib/xero-ruby/api_client.rb index 7cd762e4..23f00783 100644 --- a/lib/xero-ruby/api_client.rb +++ b/lib/xero-ruby/api_client.rb @@ -56,6 +56,10 @@ def append_to_default_config(default_config, user_config) config end + def client_id_valid? + @client_id.match?(/^[A-F,0-9]{32}$/) + end + def authorization_url url = URI.parse(@config.login_url) url.query = URI.encode_www_form( diff --git a/spec/api_client_spec.rb b/spec/api_client_spec.rb index 976f66ea..89c0733c 100644 --- a/spec/api_client_spec.rb +++ b/spec/api_client_spec.rb @@ -100,6 +100,22 @@ end end + describe 'validations' do + subject { XeroRuby::ApiClient.new(config: {}, credentials: credentials) } + + context 'when the client id is not valid' do + let(:credentials) { { client_id: '' } } + + it { is_expected.not_to be_client_id_valid } + end + + context 'when the client id is valid' do + let(:credentials) { { client_id: 'AAAAAA9E3FC416CF84283851A1BB7185' } } + + it { is_expected.to be_client_id_valid } + end + end + describe 'api_client helper functions' do let(:api_client) { XeroRuby::ApiClient.new } let(:token_set) { {'access_token': 'eyx.authorization.data', 'id_token': 'eyx.authentication.data', 'refresh_token': 'REFRESHMENTS'} }