Compare commits

...

2 Commits

Author SHA1 Message Date
Jonathan Jenne
2f5bec7bb6 Only allow predefined extensions 2023-09-25 08:51:10 +02:00
Jonathan Jenne
4e7e3ff91f catch extension being nothing 2023-09-22 14:38:17 +02:00
5 changed files with 68 additions and 6 deletions

View File

@ -84,6 +84,7 @@
<ItemGroup>
<Compile Include="Config.vb" />
<Compile Include="Modules\BaseModule.vb" />
<Compile Include="Modules\Constants.vb" />
<Compile Include="Modules\ISync.vb" />
<Compile Include="Modules\Sharepoint\Constants.vb" />
<Compile Include="Modules\Sharepoint\Entities\SharepointDocument.vb" />

View File

@ -0,0 +1,26 @@
Public Class Constants
Public Shared Property AllowedExtensions As New List(Of String) From {
"pdf",
"txt",
"pptx",
"docx",
"xlsx",
"ppt",
"doc",
"xls",
"msg",
"csv",
"dxf",
"dwg",
"jpg",
"jpeg",
"png",
"zip",
"7z",
"mp4",
"log",
"jfif",
"bmp",
"eml"
}
End Class

View File

@ -1,5 +1,4 @@
Imports System.IO
Imports DigitalData.Modules.Base
Namespace slt.Entities
Public Class sltDocument
@ -25,13 +24,33 @@ Namespace slt.Entities
End Function
Private Function GetExtension() As String
If Path.HasExtension(DocOriginalFilename) Then
Return Path.GetExtension(DocOriginalFilename)
ElseIf Path.HasExtension(Name) Then
Return Path.GetExtension(Name)
Dim oExtensionFromName = GetAllowedExtension(Name)
If oExtensionFromName IsNot Nothing Then
Return oExtensionFromName
End If
Dim oExtensionFromOriginalName = GetAllowedExtension(DocOriginalFilename)
If oExtensionFromOriginalName IsNot Nothing Then
Return oExtensionFromOriginalName
End If
Return Nothing
End Function
Private Function GetAllowedExtension(pFilename As String) As String
If Path.HasExtension(pFilename) Then
Dim oExtension = Path.GetExtension(pFilename)
Dim oExtensionWithoutDot = oExtension.Substring(1).ToLower()
If Common.Constants.AllowedExtensions.Contains(oExtensionWithoutDot) Then
Return oExtension
Else
Return Nothing
End If
Else
Return Nothing
End If
End Function
End Class
End Namespace

View File

@ -55,6 +55,11 @@ Namespace slt
Logger.Info("ExtDocId: [{0}]", oDocument.ExtDocId)
Dim oFileName = oDocument.GetUniqueFilename()
If oFileName Is Nothing Then
Throw New ApplicationException("Filename or extension could not be determined!")
End If
Dim oFilePath = GetFinalFilePath(oFileName)
If CopyFileToOutputPath(oDocument.Data, oFilePath) = False Then

View File

@ -22,6 +22,12 @@ Namespace Connectors.Test.slt
.Name = "Gutschrift-[TITEL].pdf"
}
Public oDocument4 As New sltDocument With {
.ExtDocId = "DOCID",
.DocOriginalFilename = "TWZ Einbau - Pilgerweg 8 vom 20.07.2022.jpg",
.Name = "TWZ Einbau - Pilgerweg 8 vom 20.07.2022"
}
<TestMethod>
Sub GetExtensionTest1()
Assert.AreEqual("DOCID.dwg", oDocument1.GetUniqueFilename())
@ -29,7 +35,7 @@ Namespace Connectors.Test.slt
<TestMethod>
Sub GetExtensionTest2()
Assert.AreEqual("", oDocument2.GetUniqueFilename())
Assert.AreEqual(Nothing, oDocument2.GetUniqueFilename())
End Sub
<TestMethod>
@ -37,6 +43,11 @@ Namespace Connectors.Test.slt
Assert.AreEqual("DOCID.pdf", oDocument3.GetUniqueFilename())
End Sub
<TestMethod>
Sub GetExtensionTest4()
Assert.AreEqual("DOCID.jpg", oDocument4.GetUniqueFilename())
End Sub
End Class
End Namespace