Skip to content

Commit 002284e

Browse files
authored
#184 Throw an explicit AccessDenied exception when trying to upload to a public share (#191)
1 parent dce1cd2 commit 002284e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

MegaApiClient.Tests/DownloadUpload.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ public void GetNodesFromLink_Download_Succeeds()
213213
AreStreamsEquivalent(Context.Client.Download(node), stream);
214214
}
215215

216+
[Theory]
217+
[JsonInputsDataAttribute("FolderLink")]
218+
public void UploadToPublicShare_Throws(string folderLink)
219+
{
220+
var nodes = Context.Client.GetNodesFromLink(new Uri(folderLink));
221+
var node = Assert.Single(nodes, x => x.Type == NodeType.Root);
222+
223+
var exception = Assert.Throws<ApiException>(() => Context.Client.Upload(new MemoryStream(16), "test", node));
224+
Assert.Equal(ApiResultCode.AccessDenied, exception.ApiResultCode);
225+
}
226+
216227
protected static void AreStreamsEquivalent(Stream stream1, Stream stream2)
217228
{
218229
var stream1data = new byte[stream1.Length];

MegaApiClient/MegaApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,11 @@ public INode Upload(Stream stream, string name, INode parent, DateTime? modifica
773773
throw new ArgumentException("Invalid parent node");
774774
}
775775

776+
if (parent is PublicNode)
777+
{
778+
throw new ApiException(ApiResultCode.AccessDenied);
779+
}
780+
776781
EnsureLoggedIn();
777782

778783
if (cancellationToken.HasValue)

0 commit comments

Comments
 (0)