From 2882872736875ab5cd6f3da87b65636701e6e3dc Mon Sep 17 00:00:00 2001 From: Aneesh Nireshwalia Date: Wed, 8 Feb 2023 15:10:51 -0700 Subject: [PATCH] Fix SMB test setup for Mac --- .github/workflows/tests.yml | 48 ++++++++++++++++++++++++++++---- internal/backend/smb/conpool.go | 2 +- internal/backend/smb/smb.go | 2 +- internal/backend/smb/smb_test.go | 6 +++- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d087dcbbe..dd11aacc7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,30 +21,34 @@ jobs: - job_name: Windows go: 1.19.x os: windows-latest + test_smb: true - job_name: macOS go: 1.19.x os: macOS-latest test_fuse: false - test_smb: false + test_smb: true - job_name: Linux go: 1.19.x os: ubuntu-latest test_cloud_backends: true test_fuse: true + test_smb: true check_changelog: true - job_name: Linux (race) go: 1.19.x os: ubuntu-latest test_fuse: true + test_smb: true test_opts: "-race" - job_name: Linux go: 1.18.x os: ubuntu-latest test_fuse: true + test_smb: true name: ${{ matrix.job_name }} Go ${{ matrix.go }} runs-on: ${{ matrix.os }} @@ -83,11 +87,45 @@ jobs: chmod 755 $HOME/bin/rclone rm -rf rclone* - echo "install samba" - user="smbuser" - pass="mGoWwqvgdnwtmh07" + smbuser="smbuser" + smbpass="mGoWwqvgdnwtmh07" - if [ "$RUNNER_OS" != "macOS" ]; then + if [ "$RUNNER_OS" == "macOS" ]; then + smbhome=/Users/$smbuser + echo "Get computer name" + computername=$(sudo -S scutil --get ComputerName) + echo "Create smb user" + sudo dscl . -create $smbhome + sudo dscl . -create $smbhome UserShell /bin/bash + sudo dscl . -create $smbhome RealName $smbuser + LastID=`dscl . -list /Users UniqueID | awk '{print $2}' | sort -n | tail -1` + NextID=$((LastID + 1)) + sudo dscl . -create $smbhome UniqueID $NextID + sudo dscl . -create $smbhome PrimaryGroupID 80 + sudo dscl . -create $smbhome NFSHomeDirectory $smbhome + sudo dscl . -passwd $smbhome $smbpass + sudo dscl . -append /Groups/admin GroupMembership $smbuser + echo "Make home dir" + cd /Users/ + sudo createhomedir -u $smbuser -c + sudo mkdir $smbhome/smbshare + sudo chown -R $smbuser $smbhome + sudo chmod -R 755 $smbhome + echo "Setup smb share" + sudo sharing -a $smbhome/smbshare -S smbuser -n smbuser -s 001 + echo "Enable share for os user" + sudo pwpolicy -u $smbuser -sethashtypes SMB-NT off + sudo pwpolicy -u $smbuser -enableuser + echo "Export domain" + if [[ $computername != *.local ]]; then computername=$computername".local"; fi + export RESTIC_SMB_DOMAIN=$computername + sudo pwpolicy -u $smbuser -sethashtypes SMB-NT on + sudo dscl . -passwd /Users/$smbuser $smbpass + sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.smbd.plist + sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist EnabledServices -array disk + + else + echo "install samba" sudo apt-get update sudo apt-get install samba -y diff --git a/internal/backend/smb/conpool.go b/internal/backend/smb/conpool.go index 7b2578a56..8eddcdbe6 100644 --- a/internal/backend/smb/conpool.go +++ b/internal/backend/smb/conpool.go @@ -11,7 +11,7 @@ import ( "github.com/restic/restic/internal/debug" ) -// Parts of this code have been copied from Rclone (https://github.com/rclone) +// Parts of this code have been adapted from Rclone (https://github.com/rclone) // Copyright (C) 2012 by Nick Craig-Wood http://www.craig-wood.com/nick/ // Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/internal/backend/smb/smb.go b/internal/backend/smb/smb.go index 78b3ae3c4..65e22cc0c 100644 --- a/internal/backend/smb/smb.go +++ b/internal/backend/smb/smb.go @@ -23,7 +23,7 @@ import ( "github.com/restic/restic/internal/restic" ) -// Parts of this code have been copied from Rclone (https://github.com/rclone) +// Parts of this code have been adapted from Rclone (https://github.com/rclone) // Copyright (C) 2012 by Nick Craig-Wood http://www.craig-wood.com/nick/ // Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/internal/backend/smb/smb_test.go b/internal/backend/smb/smb_test.go index 894d13c35..c210bb51b 100644 --- a/internal/backend/smb/smb_test.go +++ b/internal/backend/smb/smb_test.go @@ -2,6 +2,7 @@ package smb_test import ( "context" + "os" "testing" "github.com/google/uuid" @@ -26,7 +27,10 @@ func newTestSuite(t testing.TB) *test.Suite { cfg.Connections = smb.DefaultConnections timeout := smb.DefaultIdleTimeout cfg.IdleTimeout = timeout - cfg.Domain = smb.DefaultDomain + domain := os.Getenv("RESTIC_SMB_DOMAIN") + if domain == "" { + cfg.Domain = smb.DefaultDomain + } t.Logf("create new backend at %v", cfg.Host+"/"+cfg.ShareName)