Skip to content

Commit

Permalink
FIX: correctly handle not existing user argument for the set-user
Browse files Browse the repository at this point in the history
… function

resolves: Oldes/Rebol-issues#2547
  • Loading branch information
Oldes committed May 5, 2023
1 parent 295cf21 commit e92f1f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mezz/mezz-shell.reb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ REBOL [
Title: "REBOL 3 Mezzanine: Shell-like Command Functions"
Rights: {
Copyright 2012 REBOL Technologies
Copyright 2012-2023 Rebol Open Source Contributors
REBOL is a trademark of REBOL Technologies
}
License: {
Expand Down Expand Up @@ -72,7 +73,11 @@ su: set-user: func[
if unset? :name [su/name: none su/data: make map! 1 exit]

sys/log/info 'REBOL ["Initialize user:" as-green :name]
file: to-real-file any [file rejoin [system/options/home #"." :name %.safe]]

file: any [
all [file to-real-file file] ;@@ could to-real-file accept none?
rejoin [system/options/home #"." :name %.safe]
]
sys/log/more 'REBOL ["Checking if exists: " as-green file]
unless exists? file [
unless n [
Expand Down
11 changes: 11 additions & 0 deletions src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ if find codecs 'safe [
;- using environmental variable to avoid interactive password input using `ask`
temp: get-env "REBOL_SAFE_PASS"
set-env "REBOL_SAFE_PASS" "my-pass"
user: system/user ;; store existing user
===start-group=== "SAFE codec"
--test-- "Save/Load SAFE file"
foreach data [
Expand All @@ -772,8 +773,18 @@ if find codecs 'safe [
--assert equal? data load save %temp.safe data
delete %temp.safe
]
--test-- "Set-user which does not exists"
;@@ https://github.com/Oldes/Rebol-issues/issues/2547
--assert not error? try [set-user not-existing-user]
--test-- "Initialise new user"
--assert not error? try [set-user/n/p temp-user "passw"]
--assert system/user/name = @temp-user
--assert 'file = exists? try [system/user/data/spec/ref]
try [delete system/user/data/spec/ref]

===end-group===
set-env "REBOL_SAFE_PASS" :temp
system/user: :user
]


Expand Down

0 comments on commit e92f1f5

Please sign in to comment.