Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.
This repository was archived by the owner on May 29, 2025. It is now read-only.

verify_tokens can not be used to check if client is paired #49

@zedalaye

Description

@zedalaye

Hi,

It looks like verify_tokens can't be used to check whether the client has been paired with the BitPay server.

When no params has been passed and not tokens have been paired, it always returns true instead of false.

def verify_tokens(tokens: {})
  server_tokens={}
  tokens.each{|key, value| return false if server_tokens[key] != value}
  return true
end

If tokens is empty, it will "not" return and so pass to the next expression and then return true.

I used this code as workaround :

begin
  verified = client.verify_tokens && (tokens = client.instance_variable_get('@tokens')) && tokens.is_a?(Hash) && !tokens.empty?
rescue BitPay::BitPayError
  verified = false
end

I propose to rewrite verify_tokens as :

def verify_tokens(tokens: @tokens)
  server_tokens = refresh_tokens
  return !tokens.empty? && tokens.any? { |key, value| server_tokens[key] == value }
end

Or all? if all local tokens must match server tokens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions