-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use parameter
verbose
; spin off non-interactive parts in auth_setup
- Loading branch information
1 parent
ce170da
commit b262b9e
Showing
7 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
http_interactions: | ||
- request: | ||
method: get | ||
uri: https://emacs.ch/api/v1/accounts/verify_credentials | ||
body: | ||
encoding: '' | ||
string: '' | ||
headers: | ||
Accept: application/json, text/xml, application/xml, */* | ||
Authorization: Bearer <<<MASTODON TOKEN>>> | ||
response: | ||
status: | ||
status_code: 401 | ||
category: Client error | ||
reason: Unauthorized | ||
message: 'Client error: (401) Unauthorized' | ||
headers: | ||
date: Tue, 15 Nov 2022 14:02:14 GMT | ||
content-type: application/json; charset=utf-8 | ||
server: Mastodon | ||
x-frame-options: DENY | ||
x-content-type-options: nosniff | ||
x-xss-protection: '0' | ||
permissions-policy: interest-cohort=() | ||
x-ratelimit-limit: '300' | ||
x-ratelimit-remaining: '299' | ||
x-ratelimit-reset: '2022-11-15T14:05:00.375122Z' | ||
cache-control: no-store | ||
pragma: no-cache | ||
www-authenticate: Bearer realm="Doorkeeper", error="invalid_token", error_description="The | ||
access token is invalid" | ||
content-security-policy: 'base-uri ''none''; default-src ''none''; frame-ancestors | ||
''none''; font-src ''self'' https://emacs.ch; img-src ''self'' https: data: | ||
blob: https://emacs.ch; style-src ''self'' https://emacs.ch ''nonce-zObAiQrvdd94TojC9LPPWw==''; | ||
media-src ''self'' https: data: https://emacs.ch; frame-src ''self'' https:; | ||
manifest-src ''self'' https://emacs.ch; connect-src ''self'' data: blob: https://emacs.ch | ||
https://emacs.ch wss://emacs.ch; script-src ''self'' https://emacs.ch ''wasm-unsafe-eval''; | ||
child-src ''self'' blob: https://emacs.ch; worker-src ''self'' blob: https://emacs.ch' | ||
x-request-id: a4bc1535-e0f6-44c8-bb22-b2d8a3f8033d | ||
x-runtime: '0.008651' | ||
strict-transport-security: max-age=63072000; includeSubDomains | ||
vary: Origin | ||
body: | ||
encoding: '' | ||
file: no | ||
string: '{"error":"The access token is invalid"}' | ||
recorded_at: 2022-11-15 14:02:14 GMT | ||
recorded_with: vcr/1.1.0, webmockr/0.8.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
original_envvar <- Sys.getenv("RTOOT_DEFAULT_TOKEN") | ||
Sys.setenv(RTOOT_DEFAULT_TOKEN = "abc;user;emacs.ch") | ||
fake_token <- get_token_from_envvar() | ||
|
||
testing_path <- file.path(tempdir(), "rtoot_check") | ||
testing_name <- "testing" | ||
## we can't test the case when path is NULL because we might not be able to write to ~/ | ||
|
||
test_that("issue 72: path is FALSE", { | ||
expect_error(x <- process_created_token(token = fake_token, path = FALSE, clipboard = FALSE, verify = FALSE, verbose = FALSE), NA) | ||
expect_identical(x, fake_token) | ||
}) | ||
|
||
test_that("path is not FALSE", { | ||
expect_error(x <- process_created_token(token = fake_token, path = testing_path, clipboard = FALSE, verify = FALSE, verbose = FALSE), NA) | ||
expect_identical(x, fake_token) | ||
expect_true(file.exists(file.path(testing_path, "rtoot_token.rds"))) | ||
unlink(testing_path, recursive = TRUE) | ||
}) | ||
|
||
test_that("name is not NULL", { | ||
expect_error(x <- process_created_token(token = fake_token, name = testing_name, path = testing_path, clipboard = FALSE, verify = FALSE, verbose = FALSE), NA) | ||
expect_identical(x, fake_token) | ||
expect_true(file.exists(file.path(testing_path, paste0(testing_name, ".rds")))) | ||
unlink(testing_path, recursive = TRUE) | ||
}) | ||
|
||
test_that("clipboard and verbose", { | ||
skip_if_not(clipr::clipr_available()) | ||
expect_error(x <- process_created_token(token = fake_token, path = FALSE, clipboard = TRUE, verify = FALSE, verbose = FALSE), NA) | ||
expect_identical(x, fake_token) | ||
expect_false(dir.exists(testing_path)) | ||
expected_output <- paste0("RTOOT_DEFAULT_TOKEN=\"abc;user;emacs.ch\"") | ||
expect_equal(clipr::read_clip(), expected_output) | ||
expect_message(x <- process_created_token(token = fake_token, path = FALSE, clipboard = TRUE, verify = FALSE, verbose = TRUE)) | ||
expect_identical(x, fake_token) | ||
expect_false(dir.exists(testing_path)) | ||
}) | ||
|
||
test_that("verify", { | ||
## This is fake token; so the API call should return error if `verify` is TRUE | ||
vcr::use_cassette("process_created_token", { | ||
expect_error(x <- process_created_token(token = fake_token, path = FALSE, clipboard = FALSE, verify = TRUE, verbose = FALSE)) | ||
}) | ||
expect_error(x <- process_created_token(token = fake_token, path = FALSE, clipboard = FALSE, verify = FALSE, verbose = TRUE), NA) | ||
}) | ||
|
||
Sys.setenv(RTOOT_DEFAULT_TOKEN = original_envvar) |