summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorBoaz Yaniv <boazyan@gmail.com>2023-07-20 23:42:09 +0900
committerGitHub <noreply@github.com>2023-07-20 23:42:09 +0900
commitc0435fdff469de6046c693ad283f927428fd4910 (patch)
tree59bafaac664791664de57073cbf3343bc76ce145 /test
parent3c09c77269d848f5e7dd8f350a90e8d7ed760845 (diff)
Add API Keys for fzf --listen (#3374)
Diffstat (limited to 'test')
-rwxr-xr-xtest/test_go.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_go.rb b/test/test_go.rb
index 0062cf11..534cbba5 100755
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -16,6 +16,7 @@ UNSETS = %w[
FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS
FZF_ALT_C_COMMAND
FZF_ALT_C_OPTS FZF_CTRL_R_OPTS
+ FZF_API_KEY
fish_history
].freeze
DEFAULT_TIMEOUT = 10
@@ -2750,6 +2751,26 @@ class TestGoFZF < TestBase
end
end
+ def test_listen_with_api_key
+ post_uri = URI('http://localhost:6266')
+ tmux.send_keys 'seq 10 | FZF_API_KEY=123abc fzf --listen 6266', :Enter
+ tmux.until { |lines| assert_equal 10, lines.item_count }
+ # Incorrect API Key
+ [nil, { 'x-api-key' => '' }, { 'x-api-key' => '124abc' }].each do |headers|
+ res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)
+ assert_equal '401', res.code
+ assert_equal 'Unauthorized', res.message
+ assert_equal "invalid api key\n", res.body
+ end
+ # Valid API Key
+ [{ 'x-api-key' => '123abc' }, { 'X-API-Key' => '123abc' }].each do |headers|
+ res = Net::HTTP.post(post_uri, 'change-query(yo)+reload(seq 100)+change-prompt:hundred> ', headers)
+ assert_equal '200', res.code
+ tmux.until { |lines| assert_equal 100, lines.item_count }
+ tmux.until { |lines| assert_equal 'hundred> yo', lines[-1] }
+ end
+ end
+
def test_toggle_alternative_preview_window
tmux.send_keys "seq 10 | #{FZF} --bind space:toggle-preview --preview-window '<100000(hidden,up,border-none)' --preview 'echo /{}/{}/'", :Enter
tmux.until { |lines| assert_equal 10, lines.item_count }