Repository navigation
iclouddrive: support China Mainland GCBD accounts - #9995
Conversation
|
Hi @zsyeh, thank you for this. It's a careful piece of work, and detecting the domain from Apple's Some things to change before merging:
Minor: in Thanks again! |
|
Hi @zsyeh , Thank you for your work on bringing China Mainland iCloud Drive support to rclone! I've been following this PR closely, as this feature is particularly important for Linux users with China Mainland Apple IDs, including myself. I noticed that the maintainer provided some review feedback on October 14, but there haven't been any further updates since then. May I ask if you're planning to address the remaining review comments? Is there anything currently blocking progress? It would be great to see this feature merged and included in an upcoming stable release. And I really appreciate the effort you've already put into this. Thanks again for your work! |
8181a0a to
490c398
Compare
Thanks for following up and for your support! I plan to address the remaining review comments and push an update soon. Thanks for your patience! |
|
@ncw @CHN-CYC Thanks for the review and follow-up. I have updated this PR in
The backend tests, |
ncw
left a comment
There was a problem hiding this comment.
This is looking much better now, thank you.
See inline for the finishing touches.
Also, one-line comments on each of the new helpers setSessionRegion, saveSessionRegion, finishConfigAuthentication, endpointsForDomain would match the rest of the file.
Thank you :-)
| } | ||
|
|
||
| if err := icloud.Session.ValidateSMSCode(ctx, code, phoneID, mode); err != nil { | ||
| if errors.Is(err, api.ErrDomainChanged) { |
There was a problem hiding this comment.
This branch can never run - see above
There was a problem hiding this comment.
The SMS path has the same call chain: ValidateSMSCode -> TrustSession -> AuthWithToken -> ErrDomainChanged when accountLogin returns 302. TestValidateCodeCanChangeDomain/SMS in d1464bdd5 verifies it. I have retained this branch and retryConfigDomain pending your review of this evidence.
| } | ||
|
|
||
| if err := icloud.Session.Validate2FACode(ctx, code); err != nil { | ||
| if errors.Is(err, api.ErrDomainChanged) { |
There was a problem hiding this comment.
This branch can never trigger as the Validate functions only call the securitycode and /2sv/trust endpoints, and only AuthWithToken returns ErrDomainChanged. China accounts still work, because the domain is detected on the first NewFs via the retry loop in authenticateSession, which matches your live testing. But this code is dead, and I'd rather remove it than keep a path that looks like it does something. Could you delete those two branches and retryConfigDomain?
There was a problem hiding this comment.
I traced this through the current code: Validate2FACode calls TrustSession, which calls AuthWithToken after /2sv/trust. AuthWithToken can return ErrDomainChanged on the accountLogin 302, so this branch is reachable during config/reconnect 2FA. TestValidateCodeCanChangeDomain/trusted_device in d1464bdd5 exercises the complete call chain with a 302 response. Removing this branch would leave that domain redirect unhandled. I have kept it open for your review.
ncw
left a comment
There was a problem hiding this comment.
Hi @zsyeh, thanks for the update, and for pushing back on my point about retryConfigDomain with a test rather than just deleting it. You're right: TrustSession finishes with AuthWithToken, so ErrDomainChanged can come back from both Validate2FACode and ValidateSMSCode, and TestValidateCodeCanChangeDomain shows that nicely. Sorry for the confusion.
This looks great now - will merge - thank you :-)
Summary
Handle Apple accountLogin responses containing
{"domainToUse":"iCloud.com.cn"}for China Mainland iCloud accounts.region = chinafor GCBD remotes. Global remotes do not gain an empty region setting.regionoption acceptsglobalorchina, with automatic detection as the normal path.Fixes #8257. Related to #8587.
Verification
go test -count=1 ./backend/iclouddrive/...— passed.go vet -unreachable=false ./backend/iclouddrive/...— passed.golangci-lint run ./...— 0 issues.make rclone— passed on Linux amd64.lsd,ls, and downloading a small file succeeded. No credentials or file names are included here.make quickteston this machine is blocked by the local NFS mount environment (cmd/nfsmountmount tests fail withfsconfig() failed: NFS: mount program didn't pass remote address).GOFLAGS="-skip=TestMount|TestSubpathMount" make quicktestpassed.